RTEMS
taskdelete.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/tasksimpl.h>
22 #include <rtems/score/threadimpl.h>
23 
25  rtems_id id
26 )
27 {
28  Thread_Control *the_thread;
29  Thread_Close_context context;
30  Thread_Control *executing;
31 
32  _Thread_queue_Context_initialize( &context.Base );
33  the_thread = _Thread_Get( id, &context.Base.Lock_context.Lock_context );
34 
35  if ( the_thread == NULL ) {
36 #if defined(RTEMS_MULTIPROCESSING)
37  if ( _Thread_MP_Is_remote( id ) ) {
39  }
40 #endif
41 
42  return RTEMS_INVALID_ID;
43  }
44 
45  executing = _Thread_Executing;
46 
47  if ( the_thread == executing ) {
48  Per_CPU_Control *cpu_self;
49 
50  cpu_self = _Thread_queue_Dispatch_disable( &context.Base );
52 
53  /*
54  * The Classic tasks are neither detached nor joinable. In case of
55  * self deletion, they are detached, otherwise joinable by default.
56  */
58  executing,
59  THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED,
60  NULL
61  );
62  _Thread_Dispatch_enable( cpu_self );
63  } else {
64  _Thread_Close( the_thread, executing, &context );
65  }
66 
67  return RTEMS_SUCCESSFUL;
68 }
void _Thread_Close(Thread_Control *the_thread, Thread_Control *executing, Thread_Close_context *context)
Closes the thread.
static __inline__ Per_CPU_Control * _Thread_queue_Dispatch_disable(Thread_queue_Context *queue_context)
Disables dispatching in a critical section.
Definition: threadqimpl.h:429
void _Thread_Exit(Thread_Control *executing, Thread_Life_state set, void *exit_value)
Exits the currently executing thread.
static __inline__ void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:152
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:416
rtems_status_code rtems_task_delete(rtems_id id)
%
Definition: taskdelete.c:24
Thread_Control * _Thread_Get(Objects_Id id, ISR_lock_Context *lock_context)
Gets a thread by its identifier.
Definition: threadget.c:24
This status code indicates successful completion.
Definition: status.h:86
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
Per CPU Core Structure.
Definition: percpu.h:347
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
This status code indicates that the operation was illegal on a remote object.
Definition: status.h:177
Inlined Routines from the Thread Handler.
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
Classic Tasks Manager Implementation.