1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Threads Private Support |
---|
5 | * |
---|
6 | * This include file contains all the private support information for |
---|
7 | * POSIX threads. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2011. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_POSIX_PTHREADIMPL_H |
---|
20 | #define _RTEMS_POSIX_PTHREADIMPL_H |
---|
21 | |
---|
22 | #include <rtems/posix/pthread.h> |
---|
23 | #include <rtems/posix/config.h> |
---|
24 | #include <rtems/posix/threadsup.h> |
---|
25 | #include <rtems/score/objectimpl.h> |
---|
26 | #include <rtems/score/threadimpl.h> |
---|
27 | #include <rtems/score/assert.h> |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | /** |
---|
34 | * @addtogroup POSIX_PTHREAD |
---|
35 | */ |
---|
36 | /**@{**/ |
---|
37 | |
---|
38 | /** |
---|
39 | * The following sets the minimum stack size for POSIX threads. |
---|
40 | */ |
---|
41 | #define PTHREAD_MINIMUM_STACK_SIZE (_Stack_Minimum() * 2) |
---|
42 | |
---|
43 | /** |
---|
44 | * The following defines the information control block used to manage |
---|
45 | * this class of objects. |
---|
46 | */ |
---|
47 | POSIX_EXTERN Objects_Information _POSIX_Threads_Information; |
---|
48 | |
---|
49 | /** |
---|
50 | * This variable contains the default POSIX Thread attributes. |
---|
51 | */ |
---|
52 | extern pthread_attr_t _POSIX_Threads_Default_attributes; |
---|
53 | |
---|
54 | /** |
---|
55 | * When the user configures a set of POSIX API initialization threads, |
---|
56 | * This variable will point to the method used to initialize them. |
---|
57 | * |
---|
58 | * NOTE: It is instantiated and initialized by confdefs.h based upon |
---|
59 | * application requirements. |
---|
60 | */ |
---|
61 | extern void (*_POSIX_Threads_Initialize_user_threads_p)(void); |
---|
62 | |
---|
63 | /** |
---|
64 | * @brief POSIX threads manager initialization. |
---|
65 | * |
---|
66 | * This routine performs the initialization necessary for this manager. |
---|
67 | */ |
---|
68 | void _POSIX_Threads_Manager_initialization(void); |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief Copy POSIX Thread attribute structure. |
---|
72 | * |
---|
73 | * This routine copies the attr2 thread attribute structure |
---|
74 | * to the attr1 Thread Attribute structure. |
---|
75 | * |
---|
76 | * @param[in] dst_attr is a pointer to the thread attribute |
---|
77 | * structure to copy into. |
---|
78 | * |
---|
79 | * @param[out] src_attr is a pointer to the thread attribute |
---|
80 | * structure to copy from. |
---|
81 | */ |
---|
82 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes( |
---|
83 | pthread_attr_t *dst_attr, |
---|
84 | const pthread_attr_t *src_attr |
---|
85 | ); |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief Free POSIX control block. |
---|
89 | * |
---|
90 | * This routine frees a pthread control block to the |
---|
91 | * inactive chain of free pthread control blocks. |
---|
92 | * |
---|
93 | * @param[in] the_pthread is a pointer to the thread to free. |
---|
94 | */ |
---|
95 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free( |
---|
96 | Thread_Control *the_pthread |
---|
97 | ); |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief Map POSIX thread IDs to control blocks. |
---|
101 | * |
---|
102 | * This function maps pthread IDs to pthread control blocks. |
---|
103 | * If ID corresponds to a local pthread, then it returns |
---|
104 | * the_pthread control pointer which maps to ID and location |
---|
105 | * is set to OBJECTS_LOCAL. if the pthread ID is global and |
---|
106 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
107 | * and the_pthread is undefined. Otherwise, location is set |
---|
108 | * to OBJECTS_ERROR and the_pthread is undefined. |
---|
109 | * |
---|
110 | * @param[in] id is the id to lookup |
---|
111 | * @param[in] location points to the returned location value |
---|
112 | * |
---|
113 | * @return This methods returns a pointer to the corresponding Thread_Control. |
---|
114 | */ |
---|
115 | RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get( |
---|
116 | pthread_t id, |
---|
117 | Objects_Locations *location |
---|
118 | ); |
---|
119 | |
---|
120 | /** |
---|
121 | * @brief POSIX threads initialize user threads body. |
---|
122 | * |
---|
123 | * This routine initializes the thread attributes structure. |
---|
124 | */ |
---|
125 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes( |
---|
126 | pthread_attr_t *attr |
---|
127 | ); |
---|
128 | |
---|
129 | /** |
---|
130 | * @brief POSIX threads sporadic budget callout. |
---|
131 | * |
---|
132 | * This routine handles the sporadic scheduling algorithm. |
---|
133 | * |
---|
134 | * @param[in] the_thread is a pointer to the thread whose budget |
---|
135 | * has been exceeded. |
---|
136 | */ |
---|
137 | void _POSIX_Threads_Sporadic_budget_callout( |
---|
138 | Thread_Control *the_thread |
---|
139 | ); |
---|
140 | |
---|
141 | /** |
---|
142 | * This routine supports the sporadic scheduling algorithm. It |
---|
143 | * is scheduled to be executed at the end of each replenishment |
---|
144 | * period. In sporadic scheduling a thread will execute at a |
---|
145 | * high priority for a user specified amount of CPU time. When |
---|
146 | * it exceeds that amount of CPU time, its priority is automatically |
---|
147 | * lowered. This TSR is executed when it is time to replenish |
---|
148 | * the thread's processor budget and raise its priority. |
---|
149 | * |
---|
150 | * @param[in] id is ignored |
---|
151 | * @param[in] argument is a pointer to the Thread_Control structure |
---|
152 | * for the thread being replenished. |
---|
153 | */ |
---|
154 | void _POSIX_Threads_Sporadic_budget_TSR( |
---|
155 | Objects_Id id, |
---|
156 | void *argument |
---|
157 | ); |
---|
158 | |
---|
159 | /** |
---|
160 | * @brief Translate sched_param into SuperCore terms. |
---|
161 | * |
---|
162 | * This method translates the POSIX API sched_param into the corresponding |
---|
163 | * SuperCore settings. |
---|
164 | * |
---|
165 | * @param[in] policy is the POSIX scheduling policy |
---|
166 | * @param[in] param points to the scheduling parameter structure |
---|
167 | * @param[in] budget_algorithm points to the output CPU Budget algorithm |
---|
168 | * @param[in] budget_callout points to the output CPU Callout |
---|
169 | * |
---|
170 | * @retval 0 Indicates success. |
---|
171 | * @retval error_code POSIX error code indicating failure. |
---|
172 | */ |
---|
173 | int _POSIX_Thread_Translate_sched_param( |
---|
174 | int policy, |
---|
175 | struct sched_param *param, |
---|
176 | Thread_CPU_budget_algorithms *budget_algorithm, |
---|
177 | Thread_CPU_budget_algorithm_callout *budget_callout |
---|
178 | ); |
---|
179 | |
---|
180 | /* |
---|
181 | * rtems_pthread_attribute_compare |
---|
182 | */ |
---|
183 | int rtems_pthread_attribute_compare( |
---|
184 | const pthread_attr_t *attr1, |
---|
185 | const pthread_attr_t *attr2 |
---|
186 | ); |
---|
187 | |
---|
188 | RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void) |
---|
189 | { |
---|
190 | _Objects_Allocator_lock(); |
---|
191 | |
---|
192 | _Thread_Kill_zombies(); |
---|
193 | |
---|
194 | return (Thread_Control *) |
---|
195 | _Objects_Allocate_unprotected( &_POSIX_Threads_Information ); |
---|
196 | } |
---|
197 | |
---|
198 | /* |
---|
199 | * _POSIX_Threads_Copy_attributes |
---|
200 | */ |
---|
201 | |
---|
202 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes( |
---|
203 | pthread_attr_t *dst_attr, |
---|
204 | const pthread_attr_t *src_attr |
---|
205 | ) |
---|
206 | { |
---|
207 | *dst_attr = *src_attr; |
---|
208 | #if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__) |
---|
209 | _Assert( |
---|
210 | dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated) |
---|
211 | ); |
---|
212 | dst_attr->affinityset = &dst_attr->affinitysetpreallocated; |
---|
213 | #endif |
---|
214 | } |
---|
215 | |
---|
216 | /* |
---|
217 | * _POSIX_Threads_Free |
---|
218 | */ |
---|
219 | |
---|
220 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free ( |
---|
221 | Thread_Control *the_pthread |
---|
222 | ) |
---|
223 | { |
---|
224 | _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object ); |
---|
225 | } |
---|
226 | |
---|
227 | /* |
---|
228 | * _POSIX_Threads_Get |
---|
229 | */ |
---|
230 | |
---|
231 | RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get ( |
---|
232 | pthread_t id, |
---|
233 | Objects_Locations *location |
---|
234 | ) |
---|
235 | { |
---|
236 | return (Thread_Control *) |
---|
237 | _Objects_Get( &_POSIX_Threads_Information, (Objects_Id)id, location ); |
---|
238 | } |
---|
239 | |
---|
240 | /* |
---|
241 | * _POSIX_Threads_Initialize_attributes |
---|
242 | */ |
---|
243 | |
---|
244 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes( |
---|
245 | pthread_attr_t *attr |
---|
246 | ) |
---|
247 | { |
---|
248 | _POSIX_Threads_Copy_attributes( |
---|
249 | attr, |
---|
250 | &_POSIX_Threads_Default_attributes |
---|
251 | ); |
---|
252 | } |
---|
253 | |
---|
254 | /* |
---|
255 | * _POSIX_Threads_Is_null |
---|
256 | */ |
---|
257 | |
---|
258 | RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null ( |
---|
259 | Thread_Control *the_pthread |
---|
260 | ) |
---|
261 | { |
---|
262 | return !the_pthread; |
---|
263 | } |
---|
264 | |
---|
265 | /** @} */ |
---|
266 | |
---|
267 | #ifdef __cplusplus |
---|
268 | } |
---|
269 | #endif |
---|
270 | |
---|
271 | #endif |
---|
272 | /* end of include file */ |
---|