[cbdabc8] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Inlined Routines Associated with the SuperCore RWLock |
---|
| 5 | * |
---|
| 6 | * This include file contains all of the inlined routines associated |
---|
| 7 | * with the SuperCore RWLock. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /* |
---|
| 11 | * COPYRIGHT (c) 1989-2008. |
---|
| 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. |
---|
[cbdabc8] | 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef _RTEMS_SCORE_CORERWLOCKIMPL_H |
---|
| 20 | #define _RTEMS_SCORE_CORERWLOCKIMPL_H |
---|
| 21 | |
---|
[89fc9345] | 22 | #include <rtems/score/percpu.h> |
---|
| 23 | #include <rtems/score/status.h> |
---|
[bfd0d7a] | 24 | #include <rtems/score/thread.h> |
---|
[02c4c441] | 25 | #include <rtems/score/threadqimpl.h> |
---|
[cbdabc8] | 26 | #include <rtems/score/watchdog.h> |
---|
| 27 | |
---|
| 28 | #ifdef __cplusplus |
---|
| 29 | extern "C" { |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * @addtogroup ScoreRWLock |
---|
| 34 | */ |
---|
| 35 | /**@{**/ |
---|
| 36 | |
---|
[1e1a91ed] | 37 | #define CORE_RWLOCK_TQ_OPERATIONS &_Thread_queue_Operations_FIFO |
---|
| 38 | |
---|
[cbdabc8] | 39 | /** |
---|
| 40 | * This is used to denote that a thread is blocking waiting for |
---|
| 41 | * read-only access to the RWLock. |
---|
| 42 | */ |
---|
| 43 | #define CORE_RWLOCK_THREAD_WAITING_FOR_READ 0 |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * This is used to denote that a thread is blocking waiting for |
---|
| 47 | * write-exclusive access to the RWLock. |
---|
| 48 | */ |
---|
| 49 | #define CORE_RWLOCK_THREAD_WAITING_FOR_WRITE 1 |
---|
| 50 | |
---|
[89fc9345] | 51 | /** |
---|
| 52 | * RWLock State. |
---|
| 53 | */ |
---|
| 54 | typedef enum { |
---|
| 55 | /** This indicates the the RWLock is not currently locked. |
---|
| 56 | */ |
---|
| 57 | CORE_RWLOCK_UNLOCKED, |
---|
| 58 | /** This indicates the the RWLock is currently locked for reading. |
---|
| 59 | */ |
---|
| 60 | CORE_RWLOCK_LOCKED_FOR_READING, |
---|
| 61 | /** This indicates the the RWLock is currently locked for reading. |
---|
| 62 | */ |
---|
| 63 | CORE_RWLOCK_LOCKED_FOR_WRITING |
---|
| 64 | } CORE_RWLock_States; |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * The following defines the control block used to manage each |
---|
| 68 | * RWLock. |
---|
| 69 | */ |
---|
| 70 | typedef struct { |
---|
| 71 | /** This field is the Waiting Queue used to manage the set of tasks |
---|
| 72 | * which are blocked waiting for the RWLock to be released. |
---|
| 73 | */ |
---|
| 74 | Thread_queue_Syslock_queue Queue; |
---|
| 75 | |
---|
| 76 | /** This element is the current state of the RWLock. |
---|
| 77 | */ |
---|
| 78 | CORE_RWLock_States current_state; |
---|
| 79 | |
---|
| 80 | /** This element contains the current number of thread waiting for this |
---|
| 81 | * RWLock to be released. */ |
---|
| 82 | unsigned int number_of_readers; |
---|
| 83 | } CORE_RWLock_Control; |
---|
| 84 | |
---|
[cbdabc8] | 85 | /** |
---|
| 86 | * @brief Initialize a RWlock. |
---|
| 87 | * |
---|
| 88 | * This routine initializes the RWLock based on the parameters passed. |
---|
| 89 | * |
---|
| 90 | * @param[in] the_rwlock is the RWLock to initialize |
---|
| 91 | */ |
---|
| 92 | void _CORE_RWLock_Initialize( |
---|
[bbd6d27a] | 93 | CORE_RWLock_Control *the_rwlock |
---|
[cbdabc8] | 94 | ); |
---|
| 95 | |
---|
[02c4c441] | 96 | RTEMS_INLINE_ROUTINE void _CORE_RWLock_Destroy( |
---|
| 97 | CORE_RWLock_Control *the_rwlock |
---|
| 98 | ) |
---|
| 99 | { |
---|
[89fc9345] | 100 | (void) the_rwlock; |
---|
[02c4c441] | 101 | } |
---|
| 102 | |
---|
[89fc9345] | 103 | RTEMS_INLINE_ROUTINE Thread_Control *_CORE_RWLock_Acquire( |
---|
[631b3c8] | 104 | CORE_RWLock_Control *the_rwlock, |
---|
| 105 | Thread_queue_Context *queue_context |
---|
[84a53988] | 106 | ) |
---|
| 107 | { |
---|
[89fc9345] | 108 | ISR_Level level; |
---|
| 109 | Thread_Control *executing; |
---|
| 110 | |
---|
| 111 | _Thread_queue_Context_ISR_disable( queue_context, level ); |
---|
| 112 | _Thread_queue_Context_set_ISR_level( queue_context, level ); |
---|
| 113 | executing = _Thread_Executing; |
---|
| 114 | _Thread_queue_Queue_acquire_critical( |
---|
| 115 | &the_rwlock->Queue.Queue, |
---|
| 116 | &executing->Potpourri_stats, |
---|
| 117 | &queue_context->Lock_context.Lock_context |
---|
| 118 | ); |
---|
| 119 | |
---|
| 120 | return executing; |
---|
[84a53988] | 121 | } |
---|
| 122 | |
---|
| 123 | RTEMS_INLINE_ROUTINE void _CORE_RWLock_Release( |
---|
[631b3c8] | 124 | CORE_RWLock_Control *the_rwlock, |
---|
| 125 | Thread_queue_Context *queue_context |
---|
[84a53988] | 126 | ) |
---|
| 127 | { |
---|
[89fc9345] | 128 | _Thread_queue_Queue_release( |
---|
| 129 | &the_rwlock->Queue.Queue, |
---|
| 130 | &queue_context->Lock_context.Lock_context |
---|
| 131 | ); |
---|
[84a53988] | 132 | } |
---|
| 133 | |
---|
[cbdabc8] | 134 | /** |
---|
| 135 | * @brief Obtain RWLock for reading. |
---|
| 136 | * |
---|
| 137 | * This routine attempts to obtain the RWLock for read access. |
---|
| 138 | * |
---|
| 139 | * @param[in] the_rwlock is the RWLock to wait for |
---|
| 140 | * @param[in] wait is true if the calling thread is willing to wait |
---|
| 141 | */ |
---|
| 142 | |
---|
[dce48791] | 143 | Status_Control _CORE_RWLock_Seize_for_reading( |
---|
[631b3c8] | 144 | CORE_RWLock_Control *the_rwlock, |
---|
| 145 | bool wait, |
---|
| 146 | Thread_queue_Context *queue_context |
---|
[cbdabc8] | 147 | ); |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * @brief Obtain RWLock for writing. |
---|
| 151 | * |
---|
| 152 | * This routine attempts to obtain the RWLock for write exclusive access. |
---|
| 153 | * |
---|
| 154 | * @param[in] the_rwlock is the RWLock to wait for |
---|
| 155 | * @param[in] wait is true if the calling thread is willing to wait |
---|
| 156 | */ |
---|
[dce48791] | 157 | Status_Control _CORE_RWLock_Seize_for_writing( |
---|
[631b3c8] | 158 | CORE_RWLock_Control *the_rwlock, |
---|
| 159 | bool wait, |
---|
| 160 | Thread_queue_Context *queue_context |
---|
[cbdabc8] | 161 | ); |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * @brief Release the RWLock. |
---|
| 165 | * |
---|
| 166 | * This routine manually releases @a the_rwlock. All of the threads waiting |
---|
| 167 | * for the RWLock will be readied. |
---|
| 168 | * |
---|
| 169 | * @param[in] the_rwlock is the RWLock to surrender |
---|
| 170 | * |
---|
| 171 | * @retval Status is returned to indicate successful or failure. |
---|
| 172 | */ |
---|
[89fc9345] | 173 | Status_Control _CORE_RWLock_Surrender( CORE_RWLock_Control *the_rwlock ); |
---|
[cbdabc8] | 174 | |
---|
| 175 | /** @} */ |
---|
| 176 | |
---|
| 177 | #ifdef __cplusplus |
---|
| 178 | } |
---|
| 179 | #endif |
---|
| 180 | |
---|
| 181 | #endif |
---|
| 182 | /* end of include file */ |
---|