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 |
---|
32 | extern "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 | */ |
---|
49 | extern Thread_Information _POSIX_Threads_Information; |
---|
50 | |
---|
51 | /** |
---|
52 | * This variable contains the default POSIX Thread attributes. |
---|
53 | */ |
---|
54 | extern pthread_attr_t _POSIX_Threads_Default_attributes; |
---|
55 | |
---|
56 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert( |
---|
57 | Thread_Control *the_thread, |
---|
58 | POSIX_API_Control *api |
---|
59 | ) |
---|
60 | { |
---|
61 | the_thread->cpu_time_budget = |
---|
62 | _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget ); |
---|
63 | |
---|
64 | _Watchdog_Per_CPU_insert_relative( |
---|
65 | &api->Sporadic.Timer, |
---|
66 | _Per_CPU_Get(), |
---|
67 | _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period ) |
---|
68 | ); |
---|
69 | } |
---|
70 | |
---|
71 | void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ); |
---|
72 | |
---|
73 | /** |
---|
74 | * @brief POSIX threads sporadic budget callout. |
---|
75 | * |
---|
76 | * This routine handles the sporadic scheduling algorithm. |
---|
77 | * |
---|
78 | * @param[in] the_thread is a pointer to the thread whose budget |
---|
79 | * has been exceeded. |
---|
80 | */ |
---|
81 | void _POSIX_Threads_Sporadic_budget_callout( |
---|
82 | Thread_Control *the_thread |
---|
83 | ); |
---|
84 | |
---|
85 | /** |
---|
86 | * @brief Translate sched_param into SuperCore terms. |
---|
87 | * |
---|
88 | * This method translates the POSIX API sched_param into the corresponding |
---|
89 | * SuperCore settings. |
---|
90 | * |
---|
91 | * @param[in] policy is the POSIX scheduling policy |
---|
92 | * @param[in] param points to the scheduling parameter structure |
---|
93 | * @param[in] budget_algorithm points to the output CPU Budget algorithm |
---|
94 | * @param[in] budget_callout points to the output CPU Callout |
---|
95 | * |
---|
96 | * @retval 0 Indicates success. |
---|
97 | * @retval error_code POSIX error code indicating failure. |
---|
98 | */ |
---|
99 | int _POSIX_Thread_Translate_sched_param( |
---|
100 | int policy, |
---|
101 | struct sched_param *param, |
---|
102 | Thread_CPU_budget_algorithms *budget_algorithm, |
---|
103 | Thread_CPU_budget_algorithm_callout *budget_callout |
---|
104 | ); |
---|
105 | |
---|
106 | /* |
---|
107 | * rtems_pthread_attribute_compare |
---|
108 | */ |
---|
109 | int rtems_pthread_attribute_compare( |
---|
110 | const pthread_attr_t *attr1, |
---|
111 | const pthread_attr_t *attr2 |
---|
112 | ); |
---|
113 | |
---|
114 | RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void) |
---|
115 | { |
---|
116 | _Objects_Allocator_lock(); |
---|
117 | |
---|
118 | _Thread_Kill_zombies(); |
---|
119 | |
---|
120 | return (Thread_Control *) |
---|
121 | _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects ); |
---|
122 | } |
---|
123 | |
---|
124 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes( |
---|
125 | pthread_attr_t *dst_attr, |
---|
126 | const pthread_attr_t *src_attr |
---|
127 | ) |
---|
128 | { |
---|
129 | *dst_attr = *src_attr; |
---|
130 | #if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__) |
---|
131 | _Assert( |
---|
132 | dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated) |
---|
133 | ); |
---|
134 | dst_attr->affinityset = &dst_attr->affinitysetpreallocated; |
---|
135 | #endif |
---|
136 | } |
---|
137 | |
---|
138 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free ( |
---|
139 | Thread_Control *the_pthread |
---|
140 | ) |
---|
141 | { |
---|
142 | _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object ); |
---|
143 | } |
---|
144 | |
---|
145 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes( |
---|
146 | pthread_attr_t *attr |
---|
147 | ) |
---|
148 | { |
---|
149 | _POSIX_Threads_Copy_attributes( |
---|
150 | attr, |
---|
151 | &_POSIX_Threads_Default_attributes |
---|
152 | ); |
---|
153 | } |
---|
154 | |
---|
155 | /** @} */ |
---|
156 | |
---|
157 | #ifdef __cplusplus |
---|
158 | } |
---|
159 | #endif |
---|
160 | |
---|
161 | #endif |
---|
162 | /* end of include file */ |
---|