source: rtems/cpukit/rtems/src/taskdelete.c @ e6b31b27

4.115
Last change on this file since e6b31b27 was 1b1be254, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 09:54:49

score: Thread life cycle re-implementation

The thread deletion is now supported on SMP.

This change fixes the following PRs:

PR1814: SMP race condition between stack free and dispatch

PR2035: psxcancel reveals NULL pointer access in _Thread_queue_Extract()

The POSIX cleanup handler are now called in the right context (should be
called in the context of the terminating thread).

http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html

Add a user extension the reflects a thread termination event. This is
used to reclaim the Newlib reentrancy structure (may use file
operations), the POSIX cleanup handlers and the POSIX key destructors.

  • Property mode set to 100644
File size: 1.7 KB
Line 
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
26rtems_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( &_RTEMS_tasks_Information, the_thread->Object.id );
42          _RTEMS_tasks_MP_Send_process_packet(
43            RTEMS_TASKS_MP_ANNOUNCE_DELETE,
44            the_thread->Object.id,
45            0                                /* Not used */
46          );
47        }
48      #endif
49
50      _Thread_Close( the_thread, _Thread_Executing );
51
52      _Objects_Put( &the_thread->Object );
53      _Thread_Set_life_protection( previous_life_protection );
54      return RTEMS_SUCCESSFUL;
55
56#if defined(RTEMS_MULTIPROCESSING)
57    case OBJECTS_REMOTE:
58      _Thread_Dispatch();
59      _Thread_Set_life_protection( previous_life_protection );
60      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
61#endif
62
63    case OBJECTS_ERROR:
64      break;
65  }
66
67  _Thread_Set_life_protection( previous_life_protection );
68
69  return RTEMS_INVALID_ID;
70}
Note: See TracBrowser for help on using the repository browser.