1 | /* |
---|
2 | * RTEMS Task Manager |
---|
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.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems/system.h> |
---|
16 | #include <rtems/rtems/status.h> |
---|
17 | #include <rtems/rtems/support.h> |
---|
18 | #include <rtems/rtems/modes.h> |
---|
19 | #include <rtems/score/object.h> |
---|
20 | #include <rtems/score/stack.h> |
---|
21 | #include <rtems/score/states.h> |
---|
22 | #include <rtems/rtems/tasks.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/threadq.h> |
---|
25 | #include <rtems/score/tod.h> |
---|
26 | #include <rtems/score/userext.h> |
---|
27 | #include <rtems/score/wkspace.h> |
---|
28 | #include <rtems/score/apiext.h> |
---|
29 | #include <rtems/score/sysstate.h> |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * rtems_task_delete |
---|
34 | * |
---|
35 | * This directive allows a thread to delete itself or the thread |
---|
36 | * identified in the id field. The executive halts execution |
---|
37 | * of the thread and frees the thread control block. |
---|
38 | * |
---|
39 | * Input parameters: |
---|
40 | * id - thread id |
---|
41 | * |
---|
42 | * Output parameters: |
---|
43 | * nothing - if id is the requesting thread (always succeeds) |
---|
44 | * RTEMS_SUCCESSFUL - if successful and id is |
---|
45 | * not the requesting thread |
---|
46 | * error code - if unsuccessful |
---|
47 | */ |
---|
48 | |
---|
49 | rtems_status_code rtems_task_delete( |
---|
50 | Objects_Id id |
---|
51 | ) |
---|
52 | { |
---|
53 | register Thread_Control *the_thread; |
---|
54 | Objects_Locations location; |
---|
55 | Objects_Information *the_information; |
---|
56 | |
---|
57 | the_thread = _Thread_Get( id, &location ); |
---|
58 | switch ( location ) { |
---|
59 | |
---|
60 | case OBJECTS_REMOTE: |
---|
61 | #if defined(RTEMS_MULTIPROCESSING) |
---|
62 | _Thread_Dispatch(); |
---|
63 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
64 | #endif |
---|
65 | |
---|
66 | case OBJECTS_ERROR: |
---|
67 | return RTEMS_INVALID_ID; |
---|
68 | |
---|
69 | case OBJECTS_LOCAL: |
---|
70 | the_information = _Objects_Get_information( the_thread->Object.id ); |
---|
71 | |
---|
72 | if ( !the_information ) { |
---|
73 | _Thread_Enable_dispatch(); |
---|
74 | return RTEMS_INVALID_ID; |
---|
75 | /* This should never happen if _Thread_Get() works right */ |
---|
76 | } |
---|
77 | |
---|
78 | _Thread_Close( the_information, the_thread ); |
---|
79 | |
---|
80 | _RTEMS_tasks_Free( the_thread ); |
---|
81 | |
---|
82 | #if defined(RTEMS_MULTIPROCESSING) |
---|
83 | if ( the_thread->is_global ) { |
---|
84 | |
---|
85 | _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id ); |
---|
86 | |
---|
87 | _RTEMS_tasks_MP_Send_process_packet( |
---|
88 | RTEMS_TASKS_MP_ANNOUNCE_DELETE, |
---|
89 | the_thread->Object.id, |
---|
90 | 0 /* Not used */ |
---|
91 | ); |
---|
92 | } |
---|
93 | #endif |
---|
94 | |
---|
95 | _Thread_Enable_dispatch(); |
---|
96 | return RTEMS_SUCCESSFUL; |
---|
97 | } |
---|
98 | |
---|
99 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
100 | } |
---|