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

5
Last change on this file since d7665823 was d7665823, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/15 at 13:43:19

score: Introduce Thread_queue_Heads

Move the storage for the thread queue heads to the threads. Each thread
provides a set of thread queue heads allocated from a dedicated memory
pool. In case a thread blocks on a queue, then it lends its heads to
the queue. In case the thread unblocks, then it takes a free set of
threads from the queue. Since a thread can block on at most one queue
this works. This mechanism is used in FreeBSD. The motivation for this
change is to reduce the memory demands of the synchronization objects.
On a 32-bit uni-processor configuration the Thread_queue_Control size is
now 8 bytes, compared to 64 bytes in RTEMS 4.10 (other changes reduced
the size as well).

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