[0c5317d] | 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 |
---|
[c499856] | 16 | * http://www.rtems.org/license/LICENSE. |
---|
[0c5317d] | 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> |
---|
[a2e3f33] | 25 | #include <rtems/score/objectimpl.h> |
---|
[1b1be254] | 26 | #include <rtems/score/threadimpl.h> |
---|
[185e46f] | 27 | #include <rtems/score/assert.h> |
---|
[0c5317d] | 28 | |
---|
| 29 | #ifdef __cplusplus |
---|
| 30 | extern "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 | */ |
---|
[ef1a985f] | 47 | extern Thread_Information _POSIX_Threads_Information; |
---|
[0c5317d] | 48 | |
---|
| 49 | /** |
---|
| 50 | * This variable contains the default POSIX Thread attributes. |
---|
| 51 | */ |
---|
[185e46f] | 52 | extern pthread_attr_t _POSIX_Threads_Default_attributes; |
---|
[0c5317d] | 53 | |
---|
| 54 | /** |
---|
| 55 | * @brief POSIX threads sporadic budget callout. |
---|
| 56 | * |
---|
| 57 | * This routine handles the sporadic scheduling algorithm. |
---|
| 58 | * |
---|
| 59 | * @param[in] the_thread is a pointer to the thread whose budget |
---|
| 60 | * has been exceeded. |
---|
| 61 | */ |
---|
| 62 | void _POSIX_Threads_Sporadic_budget_callout( |
---|
| 63 | Thread_Control *the_thread |
---|
| 64 | ); |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * This routine supports the sporadic scheduling algorithm. It |
---|
| 68 | * is scheduled to be executed at the end of each replenishment |
---|
| 69 | * period. In sporadic scheduling a thread will execute at a |
---|
| 70 | * high priority for a user specified amount of CPU time. When |
---|
| 71 | * it exceeds that amount of CPU time, its priority is automatically |
---|
| 72 | * lowered. This TSR is executed when it is time to replenish |
---|
| 73 | * the thread's processor budget and raise its priority. |
---|
| 74 | * |
---|
| 75 | * @param[in] id is ignored |
---|
| 76 | * @param[in] argument is a pointer to the Thread_Control structure |
---|
| 77 | * for the thread being replenished. |
---|
| 78 | */ |
---|
[03b900d] | 79 | void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog ); |
---|
[0c5317d] | 80 | |
---|
| 81 | /** |
---|
| 82 | * @brief Translate sched_param into SuperCore terms. |
---|
| 83 | * |
---|
| 84 | * This method translates the POSIX API sched_param into the corresponding |
---|
| 85 | * SuperCore settings. |
---|
| 86 | * |
---|
| 87 | * @param[in] policy is the POSIX scheduling policy |
---|
| 88 | * @param[in] param points to the scheduling parameter structure |
---|
| 89 | * @param[in] budget_algorithm points to the output CPU Budget algorithm |
---|
| 90 | * @param[in] budget_callout points to the output CPU Callout |
---|
| 91 | * |
---|
| 92 | * @retval 0 Indicates success. |
---|
| 93 | * @retval error_code POSIX error code indicating failure. |
---|
| 94 | */ |
---|
| 95 | int _POSIX_Thread_Translate_sched_param( |
---|
| 96 | int policy, |
---|
| 97 | struct sched_param *param, |
---|
| 98 | Thread_CPU_budget_algorithms *budget_algorithm, |
---|
| 99 | Thread_CPU_budget_algorithm_callout *budget_callout |
---|
| 100 | ); |
---|
| 101 | |
---|
[185e46f] | 102 | /* |
---|
| 103 | * rtems_pthread_attribute_compare |
---|
| 104 | */ |
---|
| 105 | int rtems_pthread_attribute_compare( |
---|
| 106 | const pthread_attr_t *attr1, |
---|
| 107 | const pthread_attr_t *attr2 |
---|
| 108 | ); |
---|
[5c332349] | 109 | |
---|
[23fec9f0] | 110 | RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void) |
---|
[0c5317d] | 111 | { |
---|
[23fec9f0] | 112 | _Objects_Allocator_lock(); |
---|
| 113 | |
---|
[1b1be254] | 114 | _Thread_Kill_zombies(); |
---|
| 115 | |
---|
[23fec9f0] | 116 | return (Thread_Control *) |
---|
[d7665823] | 117 | _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects ); |
---|
[0c5317d] | 118 | } |
---|
| 119 | |
---|
[5c332349] | 120 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes( |
---|
[185e46f] | 121 | pthread_attr_t *dst_attr, |
---|
| 122 | const pthread_attr_t *src_attr |
---|
| 123 | ) |
---|
| 124 | { |
---|
| 125 | *dst_attr = *src_attr; |
---|
[69d7279] | 126 | #if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__) |
---|
[5c332349] | 127 | _Assert( |
---|
[185e46f] | 128 | dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated) |
---|
| 129 | ); |
---|
| 130 | dst_attr->affinityset = &dst_attr->affinitysetpreallocated; |
---|
| 131 | #endif |
---|
[5c332349] | 132 | } |
---|
[185e46f] | 133 | |
---|
[0c5317d] | 134 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free ( |
---|
| 135 | Thread_Control *the_pthread |
---|
| 136 | ) |
---|
| 137 | { |
---|
[d7665823] | 138 | _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object ); |
---|
[0c5317d] | 139 | } |
---|
| 140 | |
---|
[5c332349] | 141 | RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes( |
---|
| 142 | pthread_attr_t *attr |
---|
[185e46f] | 143 | ) |
---|
| 144 | { |
---|
| 145 | _POSIX_Threads_Copy_attributes( |
---|
| 146 | attr, |
---|
| 147 | &_POSIX_Threads_Default_attributes |
---|
| 148 | ); |
---|
[5c332349] | 149 | } |
---|
[185e46f] | 150 | |
---|
[0c5317d] | 151 | /** @} */ |
---|
| 152 | |
---|
| 153 | #ifdef __cplusplus |
---|
| 154 | } |
---|
| 155 | #endif |
---|
| 156 | |
---|
| 157 | #endif |
---|
| 158 | /* end of include file */ |
---|