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 | bool previous_life_protection; |
---|
33 | |
---|
34 | previous_life_protection = _Thread_Set_life_protection( true ); |
---|
35 | the_thread = _Thread_Get( id, &location ); |
---|
36 | switch ( location ) { |
---|
37 | |
---|
38 | case OBJECTS_LOCAL: |
---|
39 | #if defined(RTEMS_MULTIPROCESSING) |
---|
40 | if ( the_thread->is_global ) { |
---|
41 | _Objects_MP_Close( |
---|
42 | &_RTEMS_tasks_Information.Objects, |
---|
43 | the_thread->Object.id |
---|
44 | ); |
---|
45 | _RTEMS_tasks_MP_Send_process_packet( |
---|
46 | RTEMS_TASKS_MP_ANNOUNCE_DELETE, |
---|
47 | the_thread->Object.id, |
---|
48 | 0 /* Not used */ |
---|
49 | ); |
---|
50 | } |
---|
51 | #endif |
---|
52 | |
---|
53 | _Thread_Close( the_thread, _Thread_Executing ); |
---|
54 | |
---|
55 | _Objects_Put( &the_thread->Object ); |
---|
56 | _Thread_Set_life_protection( previous_life_protection ); |
---|
57 | return RTEMS_SUCCESSFUL; |
---|
58 | |
---|
59 | #if defined(RTEMS_MULTIPROCESSING) |
---|
60 | case OBJECTS_REMOTE: |
---|
61 | _Thread_Dispatch(); |
---|
62 | _Thread_Set_life_protection( previous_life_protection ); |
---|
63 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
64 | #endif |
---|
65 | |
---|
66 | case OBJECTS_ERROR: |
---|
67 | break; |
---|
68 | } |
---|
69 | |
---|
70 | _Thread_Set_life_protection( previous_life_protection ); |
---|
71 | |
---|
72 | return RTEMS_INVALID_ID; |
---|
73 | } |
---|