1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Delete Task |
---|
5 | * @ingroup ClassicTasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/config.h> |
---|
23 | #include <rtems/rtems/status.h> |
---|
24 | #include <rtems/rtems/support.h> |
---|
25 | #include <rtems/rtems/modes.h> |
---|
26 | #include <rtems/score/object.h> |
---|
27 | #include <rtems/score/stack.h> |
---|
28 | #include <rtems/score/states.h> |
---|
29 | #include <rtems/rtems/tasksimpl.h> |
---|
30 | #include <rtems/score/thread.h> |
---|
31 | #include <rtems/score/threadq.h> |
---|
32 | #include <rtems/score/tod.h> |
---|
33 | #include <rtems/score/wkspace.h> |
---|
34 | #include <rtems/score/apiext.h> |
---|
35 | #include <rtems/score/apimutex.h> |
---|
36 | |
---|
37 | rtems_status_code rtems_task_delete( |
---|
38 | rtems_id id |
---|
39 | ) |
---|
40 | { |
---|
41 | register Thread_Control *the_thread; |
---|
42 | Objects_Locations location; |
---|
43 | Objects_Information *the_information; |
---|
44 | |
---|
45 | #if defined( RTEMS_SMP ) |
---|
46 | if ( rtems_configuration_is_smp_enabled() ) { |
---|
47 | return RTEMS_NOT_IMPLEMENTED; |
---|
48 | } |
---|
49 | #endif |
---|
50 | |
---|
51 | _RTEMS_Lock_allocator(); |
---|
52 | |
---|
53 | the_thread = _Thread_Get( id, &location ); |
---|
54 | switch ( location ) { |
---|
55 | |
---|
56 | case OBJECTS_LOCAL: |
---|
57 | the_information = _Objects_Get_information_id( the_thread->Object.id ); |
---|
58 | |
---|
59 | #if defined(RTEMS_DEBUG) |
---|
60 | if ( !the_information ) { |
---|
61 | _Objects_Put( &the_thread->Object ); |
---|
62 | return RTEMS_INVALID_ID; |
---|
63 | /* This should never happen if _Thread_Get() works right */ |
---|
64 | } |
---|
65 | #endif |
---|
66 | |
---|
67 | #if defined(RTEMS_MULTIPROCESSING) |
---|
68 | if ( the_thread->is_global ) { |
---|
69 | _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id ); |
---|
70 | _RTEMS_tasks_MP_Send_process_packet( |
---|
71 | RTEMS_TASKS_MP_ANNOUNCE_DELETE, |
---|
72 | the_thread->Object.id, |
---|
73 | 0 /* Not used */ |
---|
74 | ); |
---|
75 | } |
---|
76 | #endif |
---|
77 | |
---|
78 | _Thread_Close( the_information, the_thread ); |
---|
79 | |
---|
80 | _RTEMS_tasks_Free( the_thread ); |
---|
81 | |
---|
82 | /* FIXME: Lock order reversal */ |
---|
83 | _RTEMS_Unlock_allocator(); |
---|
84 | _Objects_Put( &the_thread->Object ); |
---|
85 | return RTEMS_SUCCESSFUL; |
---|
86 | |
---|
87 | #if defined(RTEMS_MULTIPROCESSING) |
---|
88 | case OBJECTS_REMOTE: |
---|
89 | _RTEMS_Unlock_allocator(); |
---|
90 | _Thread_Dispatch(); |
---|
91 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
92 | #endif |
---|
93 | |
---|
94 | case OBJECTS_ERROR: |
---|
95 | break; |
---|
96 | } |
---|
97 | |
---|
98 | _RTEMS_Unlock_allocator(); |
---|
99 | return RTEMS_INVALID_ID; |
---|
100 | } |
---|