source: rtems/cpukit/posix/include/rtems/posix/pthreadimpl.h @ 185e46f

4.115
Last change on this file since 185e46f was 185e46f, checked in by Jennifer Averett <jennifer.averett@…>, on 01/31/14 at 14:54:45

posix: Add POSIX thread affinity attribute support.

With the addition of pthread affinity information in pthread_attr_t,
the existing code for pthread_attr_t had to be adjusted.

  • Property mode set to 100644
File size: 7.4 KB
Line 
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.com/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/thread.h>
27#include <rtems/score/assert.h>
28
29#ifdef __cplusplus
30extern "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 */
47POSIX_EXTERN Objects_Information  _POSIX_Threads_Information;
48
49/**
50 * This variable contains the default POSIX Thread attributes.
51 */
52extern 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 */
61extern 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 */
68void _POSIX_Threads_Manager_initialization(void);
69
70/**
71 * @brief Allocate POSIX thread control block.
72 *
73 * This function allocates a pthread control block from
74 * the inactive chain of free pthread control blocks.
75 *
76 * @return This method returns a newly allocated thread.
77 */
78RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
79
80/**
81 * @brief Copy POSIX Thread attribute structure.
82 *
83 * This routine copies the attr2 thread attribute structure
84 * to the attr1 Thread Attribute structure.
85 *
86 * @param[in] dst_attr is a pointer to the thread attribute
87 * structure to copy into.
88 *
89 * @param[out] src_attr is a pointer to the thread attribute
90 * structure to copy from.
91 */
92RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
93  pthread_attr_t        *dst_attr,
94  const pthread_attr_t  *src_attr
95);
96
97/**
98 * @brief Free POSIX control block.
99 *
100 * This routine frees a pthread control block to the
101 * inactive chain of free pthread control blocks.
102 *
103 * @param[in] the_pthread is a pointer to the thread to free.
104 */
105RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free(
106  Thread_Control *the_pthread
107);
108
109/**
110 * @brief Map POSIX thread IDs to control blocks.
111 *
112 * This function maps pthread IDs to pthread control blocks.
113 * If ID corresponds to a local pthread, then it returns
114 * the_pthread control pointer which maps to ID and location
115 * is set to OBJECTS_LOCAL.  if the pthread ID is global and
116 * resides on a remote node, then location is set to OBJECTS_REMOTE,
117 * and the_pthread is undefined.  Otherwise, location is set
118 * to OBJECTS_ERROR and the_pthread is undefined.
119 *
120 * @param[in] id is the id to lookup
121 * @param[in] location points to the returned location value
122 *
123 * @return This methods returns a pointer to the corresponding Thread_Control.
124 */
125RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get(
126  pthread_t          id,
127  Objects_Locations *location
128);
129
130/**
131 * @brief POSIX threads initialize user threads body.
132 *
133 * This routine initializes the thread attributes structure.
134 */
135RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
136  pthread_attr_t  *attr
137);
138
139/**
140 * @brief Check if a POSIX thread control block is NULL.
141 *
142 * This function returns @c TRUE if the_pthread is @c NULL and @c FALSE
143 * otherwise.
144 *
145 * @param[in] the_pthread is a pointer to the POSIX thread control block
146 * to check.
147 *
148 * @retval TRUE The thread control block is @c NULL.
149 * @retval FALSE The thread control block is not @c NULL.
150 */
151RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null(
152  Thread_Control *the_pthread
153);
154
155/**
156 * @brief POSIX threads sporadic budget callout.
157 *
158 * This routine handles the sporadic scheduling algorithm.
159 *
160 * @param[in] the_thread is a pointer to the thread whose budget
161 * has been exceeded.
162 */
163void _POSIX_Threads_Sporadic_budget_callout(
164  Thread_Control *the_thread
165);
166
167/**
168 * This routine supports the sporadic scheduling algorithm.  It
169 * is scheduled to be executed at the end of each replenishment
170 * period.  In sporadic scheduling a thread will execute at a
171 * high priority for a user specified amount of CPU time.  When
172 * it exceeds that amount of CPU time, its priority is automatically
173 * lowered. This TSR is executed when it is time to replenish
174 * the thread's processor budget and raise its priority.
175 *
176 * @param[in] id is ignored
177 * @param[in] argument is a pointer to the Thread_Control structure
178 *            for the thread being replenished.
179 */
180void _POSIX_Threads_Sporadic_budget_TSR(
181  Objects_Id      id,
182  void           *argument
183);
184
185/**
186 * @brief Translate sched_param into SuperCore terms.
187 *
188 * This method translates the POSIX API sched_param into the corresponding
189 * SuperCore settings.
190 *
191 * @param[in] policy is the POSIX scheduling policy
192 * @param[in] param points to the scheduling parameter structure
193 * @param[in] budget_algorithm points to the output CPU Budget algorithm
194 * @param[in] budget_callout points to the output CPU Callout
195 *
196 * @retval 0 Indicates success.
197 * @retval error_code POSIX error code indicating failure.
198 */
199int _POSIX_Thread_Translate_sched_param(
200  int                                  policy,
201  struct sched_param                  *param,
202  Thread_CPU_budget_algorithms        *budget_algorithm,
203  Thread_CPU_budget_algorithm_callout *budget_callout
204);
205
206/*
207 * rtems_pthread_attribute_compare
208 */
209int rtems_pthread_attribute_compare(
210  const pthread_attr_t *attr1,
211  const pthread_attr_t *attr2
212);
213 
214/*
215 *  _POSIX_Threads_Allocate
216 */
217
218RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void )
219{
220  return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information );
221}
222
223/*
224 * _POSIX_Threads_Copy_attributes
225 */
226
227RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
228  pthread_attr_t        *dst_attr,
229  const pthread_attr_t  *src_attr
230)
231{
232  *dst_attr = *src_attr;
233#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
234  _Assert(
235    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
236  );
237  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
238#endif
239}
240
241/*
242 *  _POSIX_Threads_Free
243 */
244
245RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
246  Thread_Control *the_pthread
247)
248{
249  _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object );
250}
251
252/*
253 *  _POSIX_Threads_Get
254 */
255
256RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get (
257  pthread_t          id,
258  Objects_Locations *location
259)
260{
261  return (Thread_Control *)
262    _Objects_Get( &_POSIX_Threads_Information, (Objects_Id)id, location );
263}
264
265/*
266 * _POSIX_Threads_Initialize_attributes
267 */
268
269RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
270  pthread_attr_t  *attr
271)
272{
273  _POSIX_Threads_Copy_attributes(
274    attr,
275    &_POSIX_Threads_Default_attributes
276  );
277}
278
279/*
280 *  _POSIX_Threads_Is_null
281 */
282
283RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null (
284  Thread_Control *the_pthread
285)
286{
287  return !the_pthread;
288}
289
290/** @} */
291
292#ifdef __cplusplus
293}
294#endif
295
296#endif
297/*  end of include file */
Note: See TracBrowser for help on using the repository browser.