1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Delete Task |
---|
5 | * @ingroup ClassicTasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/tasksimpl.h> |
---|
22 | #include <rtems/score/apimutex.h> |
---|
23 | #include <rtems/score/threadimpl.h> |
---|
24 | #include <rtems/config.h> |
---|
25 | |
---|
26 | rtems_status_code rtems_task_delete( |
---|
27 | rtems_id id |
---|
28 | ) |
---|
29 | { |
---|
30 | Thread_Control *the_thread; |
---|
31 | Objects_Locations location; |
---|
32 | Objects_Information *the_information; |
---|
33 | |
---|
34 | #if defined( RTEMS_SMP ) |
---|
35 | if ( rtems_configuration_is_smp_enabled() ) { |
---|
36 | return RTEMS_NOT_IMPLEMENTED; |
---|
37 | } |
---|
38 | #endif |
---|
39 | |
---|
40 | _RTEMS_Lock_allocator(); |
---|
41 | |
---|
42 | the_thread = _Thread_Get( id, &location ); |
---|
43 | switch ( location ) { |
---|
44 | |
---|
45 | case OBJECTS_LOCAL: |
---|
46 | the_information = _Objects_Get_information_id( the_thread->Object.id ); |
---|
47 | |
---|
48 | #if defined(RTEMS_DEBUG) |
---|
49 | if ( !the_information ) { |
---|
50 | _Objects_Put( &the_thread->Object ); |
---|
51 | return RTEMS_INVALID_ID; |
---|
52 | /* This should never happen if _Thread_Get() works right */ |
---|
53 | } |
---|
54 | #endif |
---|
55 | |
---|
56 | #if defined(RTEMS_MULTIPROCESSING) |
---|
57 | if ( the_thread->is_global ) { |
---|
58 | _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id ); |
---|
59 | _RTEMS_tasks_MP_Send_process_packet( |
---|
60 | RTEMS_TASKS_MP_ANNOUNCE_DELETE, |
---|
61 | the_thread->Object.id, |
---|
62 | 0 /* Not used */ |
---|
63 | ); |
---|
64 | } |
---|
65 | #endif |
---|
66 | |
---|
67 | _Thread_Close( the_information, the_thread ); |
---|
68 | |
---|
69 | _RTEMS_tasks_Free( the_thread ); |
---|
70 | |
---|
71 | /* FIXME: Lock order reversal */ |
---|
72 | _RTEMS_Unlock_allocator(); |
---|
73 | _Objects_Put( &the_thread->Object ); |
---|
74 | return RTEMS_SUCCESSFUL; |
---|
75 | |
---|
76 | #if defined(RTEMS_MULTIPROCESSING) |
---|
77 | case OBJECTS_REMOTE: |
---|
78 | _RTEMS_Unlock_allocator(); |
---|
79 | _Thread_Dispatch(); |
---|
80 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
81 | #endif |
---|
82 | |
---|
83 | case OBJECTS_ERROR: |
---|
84 | break; |
---|
85 | } |
---|
86 | |
---|
87 | _RTEMS_Unlock_allocator(); |
---|
88 | return RTEMS_INVALID_ID; |
---|
89 | } |
---|