source: rtems/cpukit/posix/src/pthreadjoin.c @ a1bfb33

4.10
Last change on this file since a1bfb33 was a1bfb33, checked in by Joel Sherrill <joel.sherrill@…>, on 09/01/11 at 18:24:57

2011-09-01 Joel Sherrill <joel.sherrilL@…>

PR 1895/cpukit

  • posix/src/mqueuerecvsupp.c, posix/src/pthreadjoin.c, score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c, score/src/timespectoticks.c: Ensure time conversions to ticks do not ignore partial tick and return 1 less than desired.
  • 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        _Thread_Enable_dispatch();
64      } else {
65        _Thread_Executing->Wait.return_argument = &return_pointer;
66        _Thread_queue_Enter_critical_section( &api->Join_List );
67        _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT );
68        _Thread_Enable_dispatch();
69
70        if ( _Thread_Executing->Wait.return_code == EINTR )
71          goto on_EINTR;
72      }
73
74      if ( value_ptr )
75        *value_ptr = return_pointer;
76      return 0;
77
78#if defined(RTEMS_MULTIPROCESSING)
79    case OBJECTS_REMOTE:
80#endif
81    case OBJECTS_ERROR:
82      break;
83  }
84
85  return ESRCH;
86}
Note: See TracBrowser for help on using the repository browser.