source: rtems/cpukit/rtems/src/taskdelete.c @ 5088d97

4.104.114.95
Last change on this file since 5088d97 was 5088d97, checked in by Joel Sherrill <joel.sherrill@…>, on 02/28/08 at 16:15:35

2008-02-28 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/task.h, itron/src/cre_tsk.c, posix/src/pthreadcreate.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/timerserver.c, score/src/threadclose.c, score/src/threadcreateidle.c, score/src/threadinitialize.c: Switch task create and delete operations to using API Allocator Mutex. This moves almost all uses of the RTEMS Workspace from dispatching disabled to mutex protected which should improve deterministic behavior. The implementation was carefully done to allow task create and delete extensions to invoke more services. In particular, a task delete extension should be able to do mutex and file operations.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-2008.
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.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/rtems/modes.h>
23#include <rtems/score/object.h>
24#include <rtems/score/stack.h>
25#include <rtems/score/states.h>
26#include <rtems/rtems/tasks.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29#include <rtems/score/tod.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32#include <rtems/score/apiext.h>
33#include <rtems/score/sysstate.h>
34#include <rtems/score/apimutex.h>
35
36/*PAGE
37 *
38 *  rtems_task_delete
39 *
40 *  This directive allows a thread to delete itself or the thread
41 *  identified in the id field.  The executive halts execution
42 *  of the thread and frees the thread control block.
43 *
44 *  Input parameters:
45 *    id - thread id
46 *
47 *  Output parameters:
48 *    nothing           - if id is the requesting thread (always succeeds)
49 *    RTEMS_SUCCESSFUL - if successful and id is
50 *                           not the requesting thread
51 *    error code        - if unsuccessful
52 */
53
54rtems_status_code rtems_task_delete(
55  Objects_Id id
56)
57{
58  register Thread_Control *the_thread;
59  Objects_Locations        location;
60  Objects_Information     *the_information;
61
62  _RTEMS_Lock_allocator();
63
64  the_thread = _Thread_Get( id, &location );
65  switch ( location ) {
66
67    case OBJECTS_LOCAL:
68      the_information = _Objects_Get_information_id( the_thread->Object.id );
69
70#if defined(RTEMS_DEBUG)
71      if ( !the_information ) {
72        _Thread_Enable_dispatch();
73        return RTEMS_INVALID_ID;
74        /* This should never happen if _Thread_Get() works right */
75      }
76#endif
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      _RTEMS_Unlock_allocator();
96      _Thread_Enable_dispatch();
97      return RTEMS_SUCCESSFUL;
98
99#if defined(RTEMS_MULTIPROCESSING)
100    case OBJECTS_REMOTE:
101      _RTEMS_Unlock_allocator();
102      _Thread_Dispatch();
103      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
104#endif
105
106    case OBJECTS_ERROR:
107      break;
108  }
109
110  _RTEMS_Unlock_allocator();
111  return RTEMS_INVALID_ID;
112}
Note: See TracBrowser for help on using the repository browser.