source: rtems/cpukit/posix/src/pthreadjoin.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: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Suspends Execution of Calling Thread until Target Thread Terminates
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147
10 *
11 *  COPYRIGHT (c) 1989-2014.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <errno.h>
25
26#include <rtems/posix/pthreadimpl.h>
27#include <rtems/score/threadimpl.h>
28#include <rtems/score/threadqimpl.h>
29
30int pthread_join(
31  pthread_t   thread,
32  void      **value_ptr
33)
34{
35  Thread_Control          *the_thread;
36  POSIX_API_Control       *api;
37  Objects_Locations        location;
38  void                    *return_pointer;
39  Thread_Control          *executing;
40
41on_EINTR:
42  the_thread = _Thread_Get( thread, &location );
43  switch ( location ) {
44
45    case OBJECTS_LOCAL:
46      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
47
48      if ( api->detachstate == PTHREAD_CREATE_DETACHED ) {
49        _Objects_Put( &the_thread->Object );
50        return EINVAL;
51      }
52
53      executing = _Thread_Executing;
54
55      if ( executing == the_thread ) {
56        _Objects_Put( &the_thread->Object );
57        return EDEADLK;
58      }
59
60      /*
61       *  Put ourself on the threads join list
62       */
63
64      if ( the_thread->current_state == STATES_WAITING_FOR_JOIN_AT_EXIT ) {
65         return_pointer = the_thread->Wait.return_argument;
66         _Thread_Clear_state( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
67      } else {
68        executing->Wait.return_argument = &return_pointer;
69        _Thread_queue_Enter_critical_section( &api->Join_List );
70        _Thread_queue_Enqueue(
71          &api->Join_List,
72          executing,
73          WATCHDOG_NO_TIMEOUT
74        );
75      }
76      _Objects_Put( &the_thread->Object );
77
78      if ( executing->Wait.return_code == EINTR )
79        goto on_EINTR;
80
81      if ( value_ptr )
82        *value_ptr = return_pointer;
83      return 0;
84
85#if defined(RTEMS_MULTIPROCESSING)
86    case OBJECTS_REMOTE:
87#endif
88    case OBJECTS_ERROR:
89      break;
90  }
91
92  return ESRCH;
93}
Note: See TracBrowser for help on using the repository browser.