source: rtems/cpukit/posix/include/rtems/posix/pthreadimpl.h @ 5d65d0dd

5
Last change on this file since 5d65d0dd was 5d65d0dd, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 15, 2016 at 6:50:29 AM

posix: Use _POSIX_Threads_Sporadic_timer_insert()

  • Property mode set to 100644
File size: 4.3 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/assert.h>
26#include <rtems/score/objectimpl.h>
27#include <rtems/score/timespec.h>
28#include <rtems/score/threadimpl.h>
29#include <rtems/score/watchdogimpl.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/**
36 * @addtogroup POSIX_PTHREAD
37 */
38/**@{**/
39
40/**
41 * The following sets the minimum stack size for POSIX threads.
42 */
43#define PTHREAD_MINIMUM_STACK_SIZE (_Stack_Minimum() * 2)
44
45/**
46 * The following defines the information control block used to manage
47 * this class of objects.
48 */
49extern Thread_Information _POSIX_Threads_Information;
50
51/**
52 * This variable contains the default POSIX Thread attributes.
53 */
54extern pthread_attr_t _POSIX_Threads_Default_attributes;
55
56RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
57  POSIX_API_Control *api
58)
59{
60  _Watchdog_Per_CPU_insert_relative(
61    &api->Sporadic_timer,
62    _Per_CPU_Get(),
63    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period )
64  );
65}
66
67/**
68 * @brief POSIX threads sporadic budget callout.
69 *
70 * This routine handles the sporadic scheduling algorithm.
71 *
72 * @param[in] the_thread is a pointer to the thread whose budget
73 * has been exceeded.
74 */
75void _POSIX_Threads_Sporadic_budget_callout(
76  Thread_Control *the_thread
77);
78
79/**
80 * This routine supports the sporadic scheduling algorithm.  It
81 * is scheduled to be executed at the end of each replenishment
82 * period.  In sporadic scheduling a thread will execute at a
83 * high priority for a user specified amount of CPU time.  When
84 * it exceeds that amount of CPU time, its priority is automatically
85 * lowered. This TSR is executed when it is time to replenish
86 * the thread's processor budget and raise its priority.
87 *
88 * @param[in] id is ignored
89 * @param[in] argument is a pointer to the Thread_Control structure
90 *            for the thread being replenished.
91 */
92void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog );
93
94/**
95 * @brief Translate sched_param into SuperCore terms.
96 *
97 * This method translates the POSIX API sched_param into the corresponding
98 * SuperCore settings.
99 *
100 * @param[in] policy is the POSIX scheduling policy
101 * @param[in] param points to the scheduling parameter structure
102 * @param[in] budget_algorithm points to the output CPU Budget algorithm
103 * @param[in] budget_callout points to the output CPU Callout
104 *
105 * @retval 0 Indicates success.
106 * @retval error_code POSIX error code indicating failure.
107 */
108int _POSIX_Thread_Translate_sched_param(
109  int                                  policy,
110  struct sched_param                  *param,
111  Thread_CPU_budget_algorithms        *budget_algorithm,
112  Thread_CPU_budget_algorithm_callout *budget_callout
113);
114
115/*
116 * rtems_pthread_attribute_compare
117 */
118int rtems_pthread_attribute_compare(
119  const pthread_attr_t *attr1,
120  const pthread_attr_t *attr2
121);
122
123RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
124{
125  _Objects_Allocator_lock();
126
127  _Thread_Kill_zombies();
128
129  return (Thread_Control *)
130    _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects );
131}
132
133RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
134  pthread_attr_t        *dst_attr,
135  const pthread_attr_t  *src_attr
136)
137{
138  *dst_attr = *src_attr;
139#if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__)
140  _Assert(
141    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
142  );
143  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
144#endif
145}
146
147RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
148  Thread_Control *the_pthread
149)
150{
151  _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object );
152}
153
154RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
155  pthread_attr_t  *attr
156)
157{
158  _POSIX_Threads_Copy_attributes(
159    attr,
160    &_POSIX_Threads_Default_attributes
161  );
162}
163
164/** @} */
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif
171/*  end of include file */
Note: See TracBrowser for help on using the repository browser.