source: rtems/cpukit/posix/src/pthreadexit.c @ f39f667a

4.115
Last change on this file since f39f667a was f39f667a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 11:50:48

score: Simplify _Thread_Change_priority()

The function to change a thread priority was too complex. Simplify it
with a new scheduler operation. This increases the average case
performance due to the simplified logic. The interrupt disabled
critical section is a bit prolonged since now the extract, update and
enqueue steps are executed atomically. This should however not impact
the worst-case interrupt latency since at least for the Deterministic
Priority Scheduler this sequence can be carried out with a wee bit of
instructions and no loops.

Add _Scheduler_Change_priority() to replace the sequence of

  • _Thread_Set_transient(),
  • _Scheduler_Extract(),
  • _Scheduler_Enqueue(), and
  • _Scheduler_Enqueue_first().

Delete STATES_TRANSIENT, _States_Is_transient() and
_Thread_Set_transient() since this state is now superfluous.

With this change it is possible to get rid of the
SCHEDULER_SMP_NODE_IN_THE_AIR state. This considerably simplifies the
implementation of the new SMP locking protocols.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Thread Exit Shared Helper
5 * @ingroup POSIX_THREAD Thread API Extension
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
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 <pthread.h>
22
23#include <rtems/posix/pthreadimpl.h>
24#include <rtems/score/assert.h>
25#include <rtems/score/apimutex.h>
26#include <rtems/score/threadimpl.h>
27#include <rtems/score/threadqimpl.h>
28
29void _POSIX_Thread_Exit(
30  Thread_Control *the_thread,
31  void           *value_ptr
32)
33{
34  Thread_Control    *unblocked;
35  POSIX_API_Control *api;
36  bool               previous_life_protection;
37
38  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
39
40  _Assert( _Debug_Is_thread_dispatching_allowed() );
41
42  previous_life_protection = _Thread_Set_life_protection( true );
43  _Thread_Disable_dispatch();
44
45  the_thread->Wait.return_argument = value_ptr;
46
47  /*
48   * Process join
49   */
50  if ( api->detachstate == PTHREAD_CREATE_JOINABLE ) {
51    unblocked = _Thread_queue_Dequeue( &api->Join_List );
52    if ( unblocked ) {
53      do {
54        *(void **)unblocked->Wait.return_argument = value_ptr;
55      } while ( (unblocked = _Thread_queue_Dequeue( &api->Join_List )) );
56    } else {
57      _Thread_Set_state( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
58      _Thread_Enable_dispatch();
59      /* now waiting for thread to arrive */
60      _Thread_Disable_dispatch();
61    }
62  }
63
64  /*
65   *  Now shut down the thread
66   */
67  _Thread_Close( the_thread, _Thread_Executing );
68
69  _Thread_Enable_dispatch();
70  _Thread_Set_life_protection( previous_life_protection );
71}
72
73void pthread_exit(
74  void  *value_ptr
75)
76{
77  _POSIX_Thread_Exit( _Thread_Get_executing(), value_ptr );
78}
Note: See TracBrowser for help on using the repository browser.