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/system.h> |
---|
26 | #include <rtems/config.h> |
---|
27 | #include <rtems/score/stack.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/wkspace.h> |
---|
30 | #include <rtems/posix/cancel.h> |
---|
31 | #include <rtems/posix/posixapi.h> |
---|
32 | #include <rtems/posix/pthreadimpl.h> |
---|
33 | #include <rtems/posix/priorityimpl.h> |
---|
34 | #include <rtems/posix/config.h> |
---|
35 | #include <rtems/rtems/config.h> |
---|
36 | |
---|
37 | static void *_POSIX_Global_construction( void *arg ) |
---|
38 | { |
---|
39 | Thread_Control *executing = _Thread_Get_executing(); |
---|
40 | Thread_Entry_information entry = executing->Start.Entry; |
---|
41 | |
---|
42 | entry.Kinds.Pointer.entry = Configuration_POSIX_API |
---|
43 | .User_initialization_threads_table[ 0 ].thread_entry; |
---|
44 | |
---|
45 | (void) arg; |
---|
46 | _Thread_Global_construction( executing, &entry ); |
---|
47 | } |
---|
48 | |
---|
49 | void _POSIX_Threads_Initialize_user_threads_body(void) |
---|
50 | { |
---|
51 | int eno; |
---|
52 | uint32_t index; |
---|
53 | uint32_t maximum; |
---|
54 | posix_initialization_threads_table *user_threads; |
---|
55 | pthread_t thread_id; |
---|
56 | pthread_attr_t attr; |
---|
57 | bool register_global_construction; |
---|
58 | void *(*thread_entry)(void *); |
---|
59 | |
---|
60 | user_threads = Configuration_POSIX_API.User_initialization_threads_table; |
---|
61 | maximum = Configuration_POSIX_API.number_of_initialization_threads; |
---|
62 | |
---|
63 | if ( !user_threads ) |
---|
64 | return; |
---|
65 | |
---|
66 | register_global_construction = |
---|
67 | Configuration_RTEMS_API.number_of_initialization_tasks == 0; |
---|
68 | |
---|
69 | /* |
---|
70 | * Be careful .. if the default attribute set changes, this may need to. |
---|
71 | * |
---|
72 | * Setting the attributes explicitly is critical, since we don't want |
---|
73 | * to inherit the idle tasks attributes. |
---|
74 | */ |
---|
75 | |
---|
76 | for ( index=0 ; index < maximum ; index++ ) { |
---|
77 | /* |
---|
78 | * There is no way for these calls to fail in this situation. |
---|
79 | */ |
---|
80 | eno = pthread_attr_init( &attr ); |
---|
81 | _Assert( eno == 0 ); |
---|
82 | eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
83 | _Assert( eno == 0 ); |
---|
84 | eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size); |
---|
85 | _Assert( eno == 0 ); |
---|
86 | |
---|
87 | thread_entry = user_threads[ index ].thread_entry; |
---|
88 | if ( thread_entry == NULL ) { |
---|
89 | _Terminate( |
---|
90 | INTERNAL_ERROR_CORE, |
---|
91 | false, |
---|
92 | INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | if ( register_global_construction ) { |
---|
97 | register_global_construction = false; |
---|
98 | thread_entry = _POSIX_Global_construction; |
---|
99 | } |
---|
100 | |
---|
101 | eno = pthread_create( |
---|
102 | &thread_id, |
---|
103 | &attr, |
---|
104 | thread_entry, |
---|
105 | NULL |
---|
106 | ); |
---|
107 | if ( eno ) |
---|
108 | _POSIX_Fatal_error( POSIX_FD_PTHREAD, eno ); |
---|
109 | } |
---|
110 | } |
---|