source: rtems/cpukit/posix/src/pthreadjoin.c @ 9c7de43

5
Last change on this file since 9c7de43 was f5d6c8b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/15 at 14:25:52

score: Delete Thread_queue_Control::timeout_status

Use a parameter for _Thread_queue_Enqueue() instead to reduce memory
usage.

  • 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#include <rtems/score/statesimpl.h>
30
31int pthread_join(
32  pthread_t   thread,
33  void      **value_ptr
34)
35{
36  Thread_Control          *the_thread;
37  POSIX_API_Control       *api;
38  Objects_Locations        location;
39  void                    *return_pointer;
40  Thread_Control          *executing;
41
42on_EINTR:
43  the_thread = _Thread_Get( thread, &location );
44  switch ( location ) {
45
46    case OBJECTS_LOCAL:
47      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
48
49      if ( api->detachstate == PTHREAD_CREATE_DETACHED ) {
50        _Objects_Put( &the_thread->Object );
51        return EINVAL;
52      }
53
54      executing = _Thread_Executing;
55
56      if ( executing == the_thread ) {
57        _Objects_Put( &the_thread->Object );
58        return EDEADLK;
59      }
60
61      /*
62       *  Put ourself on the threads join list
63       */
64
65      if ( the_thread->current_state == STATES_WAITING_FOR_JOIN_AT_EXIT ) {
66         return_pointer = the_thread->Wait.return_argument;
67         _Thread_Clear_state( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
68      } else {
69        executing->Wait.return_argument = &return_pointer;
70        _Thread_queue_Enqueue(
71          &api->Join_List,
72          executing,
73          STATES_WAITING_FOR_JOIN | STATES_INTERRUPTIBLE_BY_SIGNAL,
74          WATCHDOG_NO_TIMEOUT,
75          0
76        );
77      }
78      _Objects_Put( &the_thread->Object );
79
80      if ( executing->Wait.return_code == EINTR )
81        goto on_EINTR;
82
83      if ( value_ptr )
84        *value_ptr = return_pointer;
85      return 0;
86
87#if defined(RTEMS_MULTIPROCESSING)
88    case OBJECTS_REMOTE:
89#endif
90    case OBJECTS_ERROR:
91      break;
92  }
93
94  return ESRCH;
95}
Note: See TracBrowser for help on using the repository browser.