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 | #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 | |
---|
25 | int 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 | |
---|
35 | the_thread = _POSIX_Threads_Get( thread, &location ); |
---|
36 | switch ( location ) { |
---|
37 | case OBJECTS_ERROR: |
---|
38 | case OBJECTS_REMOTE: |
---|
39 | return ESRCH; |
---|
40 | case OBJECTS_LOCAL: |
---|
41 | api = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
42 | |
---|
43 | if ( api->detachstate == PTHREAD_CREATE_DETACHED ) { |
---|
44 | _Thread_Enable_dispatch(); |
---|
45 | return EINVAL; |
---|
46 | } |
---|
47 | |
---|
48 | if ( _Thread_Is_executing( the_thread ) ) { |
---|
49 | _Thread_Enable_dispatch(); |
---|
50 | return EDEADLK; |
---|
51 | } |
---|
52 | |
---|
53 | /* |
---|
54 | * Put ourself on the threads join list |
---|
55 | */ |
---|
56 | |
---|
57 | _Thread_Executing->Wait.return_argument = (unsigned32 *) &return_pointer; |
---|
58 | |
---|
59 | _Thread_queue_Enter_critical_section( &api->Join_List ); |
---|
60 | |
---|
61 | _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT ); |
---|
62 | |
---|
63 | _Thread_Enable_dispatch(); |
---|
64 | |
---|
65 | if ( value_ptr ) |
---|
66 | *value_ptr = return_pointer; |
---|
67 | return 0; |
---|
68 | } |
---|
69 | |
---|
70 | return POSIX_BOTTOM_REACHED(); |
---|
71 | } |
---|
72 | |
---|