source: rtems/cpukit/rtems/src/taskdelete.c @ 1240aade

5
Last change on this file since 1240aade was 125f248, checked in by Sebastian Huber <sebastian.huber@…>, on 11/16/16 at 15:39:43

score: Add thread queue enqueue callout

Replace the expected thread dispatch disable level with a thread queue
enqueue callout. This enables the use of _Thread_Dispatch_direct() in
the thread queue enqueue procedure. This avoids impossible exection
paths, e.g. Per_CPU_Control::dispatch_necessary is always true.

  • Property mode set to 100644
File size: 1.6 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/threadimpl.h>
23
24rtems_status_code rtems_task_delete(
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 ) ) {
38      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
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_Dispatch_disable_critical(
51      &context.Base.Lock_context.Lock_context
52    );
53    _ISR_lock_ISR_enable( &context.Base.Lock_context.Lock_context );
54
55    /*
56     * The Classic tasks are neither detached nor joinable.  In case of
57     * self deletion, they are detached, otherwise joinable by default.
58     */
59    _Thread_Exit(
60      executing,
61      THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED,
62      NULL
63    );
64    _Thread_Dispatch_enable( cpu_self );
65  } else {
66    _Thread_Close( the_thread, executing, &context );
67  }
68
69  return RTEMS_SUCCESSFUL;
70}
Note: See TracBrowser for help on using the repository browser.