1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Thread Exit Shared Helper |
---|
5 | * @ingroup POSIX_THREAD Thread API Extension |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <pthread.h> |
---|
22 | |
---|
23 | #include <rtems/posix/pthreadimpl.h> |
---|
24 | #include <rtems/score/assert.h> |
---|
25 | #include <rtems/score/apimutex.h> |
---|
26 | #include <rtems/score/threadimpl.h> |
---|
27 | #include <rtems/score/threadqimpl.h> |
---|
28 | |
---|
29 | void _POSIX_Thread_Exit( |
---|
30 | Thread_Control *the_thread, |
---|
31 | void *value_ptr |
---|
32 | ) |
---|
33 | { |
---|
34 | Thread_Control *unblocked; |
---|
35 | POSIX_API_Control *api; |
---|
36 | bool previous_life_protection; |
---|
37 | |
---|
38 | api = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
39 | |
---|
40 | _Assert( _Debug_Is_thread_dispatching_allowed() ); |
---|
41 | |
---|
42 | previous_life_protection = _Thread_Set_life_protection( true ); |
---|
43 | _Thread_Disable_dispatch(); |
---|
44 | |
---|
45 | the_thread->Wait.return_argument = value_ptr; |
---|
46 | |
---|
47 | /* |
---|
48 | * Process join |
---|
49 | */ |
---|
50 | if ( api->detachstate == PTHREAD_CREATE_JOINABLE ) { |
---|
51 | unblocked = _POSIX_Threads_Join_dequeue( api ); |
---|
52 | if ( unblocked ) { |
---|
53 | do { |
---|
54 | *(void **)unblocked->Wait.return_argument = value_ptr; |
---|
55 | } while ( ( unblocked = _POSIX_Threads_Join_dequeue( api ) ) ); |
---|
56 | } else { |
---|
57 | _Thread_Set_state( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT ); |
---|
58 | _Thread_Enable_dispatch(); |
---|
59 | /* now waiting for thread to arrive */ |
---|
60 | _Thread_Disable_dispatch(); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | /* |
---|
65 | * Now shut down the thread |
---|
66 | */ |
---|
67 | _Thread_Close( the_thread, _Thread_Executing ); |
---|
68 | |
---|
69 | _Thread_Enable_dispatch(); |
---|
70 | _Thread_Set_life_protection( previous_life_protection ); |
---|
71 | } |
---|
72 | |
---|
73 | void pthread_exit( |
---|
74 | void *value_ptr |
---|
75 | ) |
---|
76 | { |
---|
77 | _POSIX_Thread_Exit( _Thread_Get_executing(), value_ptr ); |
---|
78 | RTEMS_UNREACHABLE(); |
---|
79 | } |
---|