1 | /* |
---|
2 | * rtems_task_variable_delete - Delete a per-task variable |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/system.h> |
---|
20 | #include <rtems/rtems/tasks.h> |
---|
21 | #include <rtems/score/wkspace.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * rtems_task_variable_delete |
---|
25 | * |
---|
26 | * This directive removes a task variable. |
---|
27 | */ |
---|
28 | |
---|
29 | rtems_status_code rtems_task_variable_delete( |
---|
30 | rtems_id tid, |
---|
31 | void **ptr |
---|
32 | ) |
---|
33 | { |
---|
34 | Thread_Control *the_thread; |
---|
35 | Objects_Locations location; |
---|
36 | rtems_task_variable_t *tvp, *prev; |
---|
37 | |
---|
38 | if ( !ptr ) |
---|
39 | return RTEMS_INVALID_ADDRESS; |
---|
40 | |
---|
41 | prev = NULL; |
---|
42 | |
---|
43 | the_thread = _Thread_Get (tid, &location); |
---|
44 | switch (location) { |
---|
45 | case OBJECTS_REMOTE: |
---|
46 | #if defined(RTEMS_MULTIPROCESSING) |
---|
47 | _Thread_Dispatch(); |
---|
48 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
49 | #endif |
---|
50 | |
---|
51 | case OBJECTS_ERROR: |
---|
52 | return RTEMS_INVALID_ID; |
---|
53 | |
---|
54 | default: |
---|
55 | return RTEMS_INTERNAL_ERROR; |
---|
56 | |
---|
57 | case OBJECTS_LOCAL: |
---|
58 | tvp = the_thread->task_variables; |
---|
59 | while (tvp) { |
---|
60 | if (tvp->ptr == ptr) { |
---|
61 | if (prev) prev->next = tvp->next; |
---|
62 | else the_thread->task_variables = tvp->next; |
---|
63 | if (tvp->dtor) |
---|
64 | (*tvp->dtor)(*tvp->ptr); |
---|
65 | if (_Thread_Is_executing(the_thread)) |
---|
66 | *tvp->ptr = tvp->gval; |
---|
67 | _Workspace_Free(tvp); |
---|
68 | _Thread_Enable_dispatch(); |
---|
69 | return RTEMS_SUCCESSFUL; |
---|
70 | } |
---|
71 | prev = tvp; |
---|
72 | tvp = tvp->next; |
---|
73 | } |
---|
74 | _Thread_Enable_dispatch(); |
---|
75 | return RTEMS_INVALID_ADDRESS; |
---|
76 | } |
---|
77 | |
---|
78 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
79 | } |
---|