source: rtems/cpukit/posix/src/pthreadjoin.c @ 07332ae

4.115
Last change on this file since 07332ae was 07332ae, checked in by Sebastian Huber <sebastian.huber@…>, on 08/22/13 at 13:20:06

score: _Thread_queue_Enqueue_with_handler()

Add thread parameter to _Thread_queue_Enqueue_with_handler() to avoid
access to global _Thread_Executing.

  • Property mode set to 100644
File size: 2.3 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-2011.
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.com/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  register 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 ==
65             (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) ) {
66         return_pointer = the_thread->Wait.return_argument;
67         _Thread_Clear_state(
68           the_thread,
69           (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT)
70         );
71      } else {
72        executing->Wait.return_argument = &return_pointer;
73        _Thread_queue_Enter_critical_section( &api->Join_List );
74        _Thread_queue_Enqueue(
75          &api->Join_List,
76          executing,
77          WATCHDOG_NO_TIMEOUT
78        );
79      }
80      _Objects_Put( &the_thread->Object );
81
82      if ( executing->Wait.return_code == EINTR )
83        goto on_EINTR;
84
85      if ( value_ptr )
86        *value_ptr = return_pointer;
87      return 0;
88
89#if defined(RTEMS_MULTIPROCESSING)
90    case OBJECTS_REMOTE:
91#endif
92    case OBJECTS_ERROR:
93      break;
94  }
95
96  return ESRCH;
97}
Note: See TracBrowser for help on using the repository browser.