1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Threads Initialize User Threads Body |
---|
5 | * @ingroup POSIX_PTHREAD |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
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 <rtems/posix/pthread.h> |
---|
22 | |
---|
23 | #include <pthread.h> |
---|
24 | |
---|
25 | #include <rtems/score/assert.h> |
---|
26 | #include <rtems/score/threadimpl.h> |
---|
27 | #include <rtems/score/interr.h> |
---|
28 | |
---|
29 | void _POSIX_Threads_Initialize_user_thread( void ) |
---|
30 | { |
---|
31 | int eno; |
---|
32 | const posix_initialization_threads_table *user_thread; |
---|
33 | pthread_t thread_id; |
---|
34 | pthread_attr_t attr; |
---|
35 | |
---|
36 | user_thread = &_POSIX_Threads_User_thread_table; |
---|
37 | |
---|
38 | /* |
---|
39 | * Be careful .. if the default attribute set changes, this may need to. |
---|
40 | * |
---|
41 | * Setting the attributes explicitly is critical, since we don't want |
---|
42 | * to inherit the idle tasks attributes. |
---|
43 | */ |
---|
44 | |
---|
45 | /* |
---|
46 | * There is no way for these calls to fail in this situation. |
---|
47 | */ |
---|
48 | eno = pthread_attr_init( &attr ); |
---|
49 | _Assert( eno == 0 ); |
---|
50 | eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
51 | _Assert( eno == 0 ); |
---|
52 | eno = pthread_attr_setstacksize( &attr, user_thread->stack_size ); |
---|
53 | _Assert( eno == 0 ); |
---|
54 | |
---|
55 | eno = pthread_create( |
---|
56 | &thread_id, |
---|
57 | &attr, |
---|
58 | user_thread->thread_entry, |
---|
59 | NULL |
---|
60 | ); |
---|
61 | if ( eno != 0 ) { |
---|
62 | _Internal_error( INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED ); |
---|
63 | } |
---|
64 | |
---|
65 | if ( _Thread_Global_constructor == 0 ) { |
---|
66 | _Thread_Global_constructor = thread_id; |
---|
67 | } |
---|
68 | } |
---|