1 | /* |
---|
2 | * rtems_task_variable_add - Add a per-task variable |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/tasks.h> |
---|
18 | #include <rtems/score/wkspace.h> |
---|
19 | |
---|
20 | /* |
---|
21 | * rtems_task_variable_add |
---|
22 | * |
---|
23 | * This directive registers a task variable. |
---|
24 | */ |
---|
25 | |
---|
26 | rtems_status_code rtems_task_variable_add( |
---|
27 | rtems_id tid, |
---|
28 | int *ptr |
---|
29 | ) |
---|
30 | { |
---|
31 | Thread_Control *the_thread; |
---|
32 | Objects_Locations location; |
---|
33 | RTEMS_API_Control *api; |
---|
34 | rtems_task_variable_t *tvp, *new; |
---|
35 | |
---|
36 | the_thread = _Thread_Get (tid, &location); |
---|
37 | switch (location) { |
---|
38 | case OBJECTS_REMOTE: |
---|
39 | #if defined(RTEMS_MULTIPROCESSING) |
---|
40 | _Thread_Dispatch(); |
---|
41 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
42 | #endif |
---|
43 | |
---|
44 | case OBJECTS_ERROR: |
---|
45 | return RTEMS_INVALID_ID; |
---|
46 | |
---|
47 | default: |
---|
48 | return RTEMS_INTERNAL_ERROR; |
---|
49 | |
---|
50 | case OBJECTS_LOCAL: |
---|
51 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
52 | |
---|
53 | /* |
---|
54 | * Figure out if the variable is already in this task's list. |
---|
55 | */ |
---|
56 | |
---|
57 | tvp = api->task_variables; |
---|
58 | while (tvp) { |
---|
59 | if (tvp->ptr == ptr) { |
---|
60 | _Thread_Enable_dispatch(); |
---|
61 | return RTEMS_SUCCESSFUL; |
---|
62 | } |
---|
63 | tvp = tvp->next; |
---|
64 | } |
---|
65 | |
---|
66 | /* |
---|
67 | * Now allocate memory for this task variable. |
---|
68 | */ |
---|
69 | |
---|
70 | new = (struct rtems_task_variable_t *) |
---|
71 | _Workspace_Allocate(sizeof(struct rtems_task_variable_t)); |
---|
72 | if (new == NULL) { |
---|
73 | _Thread_Enable_dispatch(); |
---|
74 | return RTEMS_NO_MEMORY; |
---|
75 | } |
---|
76 | new->var = 0; |
---|
77 | new->ptr = ptr; |
---|
78 | |
---|
79 | new->next = api->task_variables; |
---|
80 | api->task_variables = new; |
---|
81 | _Thread_Enable_dispatch(); |
---|
82 | return RTEMS_SUCCESSFUL; |
---|
83 | } |
---|
84 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
85 | } |
---|
86 | |
---|