source: rtems/cpukit/posix/include/rtems/posix/pthreadimpl.h @ ef1a985f

5
Last change on this file since ef1a985f was ef1a985f, checked in by Sebastian Huber <sebastian.huber@…>, on 12/11/15 at 09:47:22

Optional POSIX Threads initialization

Update #2408.

  • Property mode set to 100644
File size: 5.5 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.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
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 */
47extern Thread_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 Copy POSIX Thread attribute structure.
65 *
66 * This routine copies the attr2 thread attribute structure
67 * to the attr1 Thread Attribute structure.
68 *
69 * @param[in] dst_attr is a pointer to the thread attribute
70 * structure to copy into.
71 *
72 * @param[out] src_attr is a pointer to the thread attribute
73 * structure to copy from.
74 */
75RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
76  pthread_attr_t        *dst_attr,
77  const pthread_attr_t  *src_attr
78);
79
80/**
81 * @brief Free POSIX control block.
82 *
83 * This routine frees a pthread control block to the
84 * inactive chain of free pthread control blocks.
85 *
86 * @param[in] the_pthread is a pointer to the thread to free.
87 */
88RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free(
89  Thread_Control *the_pthread
90);
91
92/**
93 * @brief POSIX threads initialize user threads body.
94 *
95 * This routine initializes the thread attributes structure.
96 */
97RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
98  pthread_attr_t  *attr
99);
100
101/**
102 * @brief POSIX threads sporadic budget callout.
103 *
104 * This routine handles the sporadic scheduling algorithm.
105 *
106 * @param[in] the_thread is a pointer to the thread whose budget
107 * has been exceeded.
108 */
109void _POSIX_Threads_Sporadic_budget_callout(
110  Thread_Control *the_thread
111);
112
113/**
114 * This routine supports the sporadic scheduling algorithm.  It
115 * is scheduled to be executed at the end of each replenishment
116 * period.  In sporadic scheduling a thread will execute at a
117 * high priority for a user specified amount of CPU time.  When
118 * it exceeds that amount of CPU time, its priority is automatically
119 * lowered. This TSR is executed when it is time to replenish
120 * the thread's processor budget and raise its priority.
121 *
122 * @param[in] id is ignored
123 * @param[in] argument is a pointer to the Thread_Control structure
124 *            for the thread being replenished.
125 */
126void _POSIX_Threads_Sporadic_budget_TSR(
127  Objects_Id      id,
128  void           *argument
129);
130
131/**
132 * @brief Translate sched_param into SuperCore terms.
133 *
134 * This method translates the POSIX API sched_param into the corresponding
135 * SuperCore settings.
136 *
137 * @param[in] policy is the POSIX scheduling policy
138 * @param[in] param points to the scheduling parameter structure
139 * @param[in] budget_algorithm points to the output CPU Budget algorithm
140 * @param[in] budget_callout points to the output CPU Callout
141 *
142 * @retval 0 Indicates success.
143 * @retval error_code POSIX error code indicating failure.
144 */
145int _POSIX_Thread_Translate_sched_param(
146  int                                  policy,
147  struct sched_param                  *param,
148  Thread_CPU_budget_algorithms        *budget_algorithm,
149  Thread_CPU_budget_algorithm_callout *budget_callout
150);
151
152/*
153 * rtems_pthread_attribute_compare
154 */
155int rtems_pthread_attribute_compare(
156  const pthread_attr_t *attr1,
157  const pthread_attr_t *attr2
158);
159
160RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
161{
162  _Objects_Allocator_lock();
163
164  _Thread_Kill_zombies();
165
166  return (Thread_Control *)
167    _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects );
168}
169
170/*
171 * _POSIX_Threads_Copy_attributes
172 */
173
174RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
175  pthread_attr_t        *dst_attr,
176  const pthread_attr_t  *src_attr
177)
178{
179  *dst_attr = *src_attr;
180#if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__)
181  _Assert(
182    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
183  );
184  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
185#endif
186}
187
188/*
189 *  _POSIX_Threads_Free
190 */
191
192RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
193  Thread_Control *the_pthread
194)
195{
196  _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object );
197}
198
199/*
200 * _POSIX_Threads_Initialize_attributes
201 */
202
203RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
204  pthread_attr_t  *attr
205)
206{
207  _POSIX_Threads_Copy_attributes(
208    attr,
209    &_POSIX_Threads_Default_attributes
210  );
211}
212
213/*
214 *  _POSIX_Threads_Is_null
215 */
216
217RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null (
218  Thread_Control *the_pthread
219)
220{
221  return !the_pthread;
222}
223
224/** @} */
225
226#ifdef __cplusplus
227}
228#endif
229
230#endif
231/*  end of include file */
Note: See TracBrowser for help on using the repository browser.