[5aa5560] | 1 | /* |
---|
| 2 | * rtems_task_variable_delete - Delete a per-task variable |
---|
| 3 | * |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[5aa5560] | 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 |
---|
[7a39c88] | 10 | * http://www.rtems.com/license/LICENSE. |
---|
[5aa5560] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include <rtems/system.h> |
---|
| 16 | #include <rtems/rtems/tasks.h> |
---|
| 17 | #include <rtems/score/wkspace.h> |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | * rtems_task_variable_delete |
---|
| 21 | * |
---|
| 22 | * This directive removes a task variable. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | rtems_status_code rtems_task_variable_delete( |
---|
| 26 | rtems_id tid, |
---|
[c941a98] | 27 | void **ptr |
---|
[5aa5560] | 28 | ) |
---|
| 29 | { |
---|
[95bb279] | 30 | Thread_Control *the_thread; |
---|
| 31 | Objects_Locations location; |
---|
| 32 | rtems_task_variable_t *tvp, *prev; |
---|
[5aa5560] | 33 | |
---|
[17bbadd] | 34 | if ( !ptr ) |
---|
| 35 | return RTEMS_INVALID_ADDRESS; |
---|
| 36 | |
---|
[5aa5560] | 37 | prev = NULL; |
---|
| 38 | |
---|
| 39 | the_thread = _Thread_Get (tid, &location); |
---|
| 40 | switch (location) { |
---|
| 41 | case OBJECTS_REMOTE: |
---|
| 42 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 43 | _Thread_Dispatch(); |
---|
| 44 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
| 45 | #endif |
---|
| 46 | |
---|
| 47 | case OBJECTS_ERROR: |
---|
| 48 | return RTEMS_INVALID_ID; |
---|
| 49 | |
---|
| 50 | default: |
---|
| 51 | return RTEMS_INTERNAL_ERROR; |
---|
| 52 | |
---|
| 53 | case OBJECTS_LOCAL: |
---|
[aad726e] | 54 | tvp = the_thread->task_variables; |
---|
[5aa5560] | 55 | while (tvp) { |
---|
| 56 | if (tvp->ptr == ptr) { |
---|
| 57 | if (prev) prev->next = tvp->next; |
---|
[aad726e] | 58 | else the_thread->task_variables = tvp->next; |
---|
[a3b4632] | 59 | if (_Thread_Is_executing(the_thread)) { |
---|
| 60 | if (tvp->dtor) |
---|
| 61 | (*tvp->dtor)(*tvp->ptr); |
---|
[df49c60] | 62 | *tvp->ptr = tvp->gval; |
---|
[a3b4632] | 63 | } else { |
---|
| 64 | if (tvp->dtor) |
---|
| 65 | (*tvp->dtor)(tvp->tval); |
---|
| 66 | } |
---|
[5aa5560] | 67 | _Workspace_Free(tvp); |
---|
[5bda3a9] | 68 | _Thread_Enable_dispatch(); |
---|
[5aa5560] | 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 | } |
---|