source: rtems/cpukit/posix/src/pthreadjoin.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147
3 *
4 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14
15#include <pthread.h>
16#include <errno.h>
17
18#include <rtems/system.h>
19#include <rtems/score/thread.h>
20#include <rtems/posix/pthread.h>
21
22int pthread_join(
23  pthread_t   thread,
24  void      **value_ptr
25)
26{
27  register Thread_Control *the_thread;
28  POSIX_API_Control       *api;
29  Objects_Locations        location;
30  void                    *return_pointer;
31
32  the_thread = _POSIX_Threads_Get( thread, &location );
33  switch ( location ) {
34    case OBJECTS_ERROR:
35    case OBJECTS_REMOTE:
36      return ESRCH;
37    case OBJECTS_LOCAL:
38      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
39
40      if ( api->detachstate == PTHREAD_CREATE_DETACHED ) {
41        _Thread_Enable_dispatch();
42        return EINVAL;
43      }
44
45      if ( _Thread_Is_executing( the_thread ) ) {
46        _Thread_Enable_dispatch();
47        return EDEADLK;
48      }
49
50      /*
51       *  Put ourself on the threads join list
52       */
53
54      _Thread_Executing->Wait.return_argument = (unsigned32 *) &return_pointer;
55
56      _Thread_queue_Enter_critical_section( &api->Join_List );
57
58      _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT );
59
60      _Thread_Enable_dispatch();
61
62      if ( value_ptr )
63        *value_ptr = return_pointer;
64      return 0;
65  }
66
67  return POSIX_BOTTOM_REACHED();
68}
69
Note: See TracBrowser for help on using the repository browser.