source: rtems/cpukit/posix/src/pthreadjoin.c @ 426eb35

4.10
Last change on this file since 426eb35 was 426eb35, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/11 at 22:40:43

2011-07-31 Joel Sherrill <joel.sherrilL@…>

PR 1855/cpukit

  • posix/src/psignal.c, posix/src/psignalunblockthread.c, posix/src/pthread.c, posix/src/pthreadjoin.c: Correct signal processing during pthread_join. We are supposed to unblock the thread waiting on a pthread_join(), dispatch the signal handler, account for it potentially overwriting errno, and then have the thread return to blocking within pthread_join().
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147
3 *
4 *  COPYRIGHT (c) 1989-2011.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19#include <errno.h>
20
21#include <rtems/system.h>
22#include <rtems/score/thread.h>
23#include <rtems/posix/pthread.h>
24
25int pthread_join(
26  pthread_t   thread,
27  void      **value_ptr
28)
29{
30  register Thread_Control *the_thread;
31  POSIX_API_Control       *api;
32  Objects_Locations        location;
33  void                    *return_pointer;
34
35on_EINTR:
36  the_thread = _Thread_Get( thread, &location );
37  switch ( location ) {
38
39    case OBJECTS_LOCAL:
40      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
41
42      if ( api->detachstate == PTHREAD_CREATE_DETACHED ) {
43        _Thread_Enable_dispatch();
44        return EINVAL;
45      }
46
47      if ( _Thread_Is_executing( the_thread ) ) {
48        _Thread_Enable_dispatch();
49        return EDEADLK;
50      }
51
52      /*
53       *  Put ourself on the threads join list
54       */
55
56      if ( the_thread->current_state ==
57             (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) ) {
58         return_pointer = the_thread->Wait.return_argument;
59         _Thread_Clear_state(
60           the_thread,
61           (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT)
62         );
63      } else {
64        _Thread_Executing->Wait.return_argument = &return_pointer;
65        _Thread_queue_Enter_critical_section( &api->Join_List );
66        _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT );
67      }
68      _Thread_Enable_dispatch();
69
70      if ( _Thread_Executing->Wait.return_code == EINTR )
71        goto on_EINTR;
72
73      if ( value_ptr )
74        *value_ptr = return_pointer;
75      return 0;
76
77#if defined(RTEMS_MULTIPROCESSING)
78    case OBJECTS_REMOTE:
79#endif
80    case OBJECTS_ERROR:
81      break;
82  }
83
84  return ESRCH;
85}
Note: See TracBrowser for help on using the repository browser.