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 <errno.h> |
---|
22 | #include <pthread.h> |
---|
23 | #include <limits.h> |
---|
24 | |
---|
25 | #include <rtems/config.h> |
---|
26 | #include <rtems/score/stack.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #include <rtems/posix/posixapi.h> |
---|
30 | #include <rtems/posix/pthreadimpl.h> |
---|
31 | #include <rtems/posix/priorityimpl.h> |
---|
32 | #include <rtems/posix/config.h> |
---|
33 | |
---|
34 | void _POSIX_Threads_Initialize_user_threads_body(void) |
---|
35 | { |
---|
36 | int eno; |
---|
37 | uint32_t index; |
---|
38 | uint32_t maximum; |
---|
39 | posix_initialization_threads_table *user_threads; |
---|
40 | pthread_t thread_id; |
---|
41 | pthread_attr_t attr; |
---|
42 | |
---|
43 | user_threads = _Configuration_POSIX_Initialization_threads; |
---|
44 | maximum = _Configuration_POSIX_Initialization_thread_count; |
---|
45 | |
---|
46 | if ( !user_threads ) |
---|
47 | return; |
---|
48 | |
---|
49 | /* |
---|
50 | * Be careful .. if the default attribute set changes, this may need to. |
---|
51 | * |
---|
52 | * Setting the attributes explicitly is critical, since we don't want |
---|
53 | * to inherit the idle tasks attributes. |
---|
54 | */ |
---|
55 | |
---|
56 | for ( index=0 ; index < maximum ; index++ ) { |
---|
57 | /* |
---|
58 | * There is no way for these calls to fail in this situation. |
---|
59 | */ |
---|
60 | eno = pthread_attr_init( &attr ); |
---|
61 | _Assert( eno == 0 ); |
---|
62 | eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
63 | _Assert( eno == 0 ); |
---|
64 | eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size); |
---|
65 | _Assert( eno == 0 ); |
---|
66 | |
---|
67 | eno = pthread_create( |
---|
68 | &thread_id, |
---|
69 | &attr, |
---|
70 | user_threads[ index ].thread_entry, |
---|
71 | NULL |
---|
72 | ); |
---|
73 | if ( eno != 0 ) { |
---|
74 | _Internal_error( INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED ); |
---|
75 | } |
---|
76 | |
---|
77 | if ( _Thread_Global_constructor == 0 ) { |
---|
78 | _Thread_Global_constructor = thread_id; |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|