[c71b596] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Inlined Routines Associated with the SuperCore Spinlock |
---|
| 5 | * |
---|
| 6 | * This include file contains all of the inlined routines associated |
---|
| 7 | * with the SuperCore spinlock. |
---|
| 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. |
---|
[c71b596] | 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef _RTEMS_SCORE_CORESPINLOCKIMPL_H |
---|
| 20 | #define _RTEMS_SCORE_CORESPINLOCKIMPL_H |
---|
| 21 | |
---|
| 22 | #include <rtems/score/corespinlock.h> |
---|
| 23 | #include <rtems/score/watchdog.h> |
---|
| 24 | |
---|
| 25 | #ifdef __cplusplus |
---|
| 26 | extern "C" { |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * @addtogroup ScoreSpinlock |
---|
| 31 | */ |
---|
| 32 | /**@{**/ |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Core Spinlock handler return statuses. |
---|
| 36 | */ |
---|
| 37 | typedef enum { |
---|
| 38 | /** This status indicates that the operation completed successfully. */ |
---|
| 39 | CORE_SPINLOCK_SUCCESSFUL, |
---|
| 40 | /** This status indicates that the current thread already holds the spinlock. |
---|
| 41 | * An attempt to relock it will result in deadlock. |
---|
| 42 | */ |
---|
| 43 | CORE_SPINLOCK_HOLDER_RELOCKING, |
---|
| 44 | /** This status indicates that the current thread is attempting to unlock a |
---|
| 45 | * spinlock that is held by another thread. |
---|
| 46 | */ |
---|
| 47 | CORE_SPINLOCK_NOT_HOLDER, |
---|
| 48 | /** This status indicates that a thread reached the limit of time it |
---|
| 49 | * was willing to wait on the spin lock. |
---|
| 50 | */ |
---|
| 51 | CORE_SPINLOCK_TIMEOUT, |
---|
| 52 | /** This status indicates that a thread is currently waiting for this |
---|
| 53 | * spin lock. |
---|
| 54 | */ |
---|
| 55 | CORE_SPINLOCK_IS_BUSY, |
---|
| 56 | /** This status indicates that the spinlock is currently locked and thus |
---|
| 57 | * unavailable. |
---|
| 58 | */ |
---|
[3f72dda6] | 59 | CORE_SPINLOCK_UNAVAILABLE |
---|
[c71b596] | 60 | } CORE_spinlock_Status; |
---|
| 61 | |
---|
| 62 | /** This is a shorthand for the last status code. */ |
---|
[3f72dda6] | 63 | #define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_UNAVAILABLE |
---|
[c71b596] | 64 | |
---|
| 65 | /** This indicates the lock is available. */ |
---|
| 66 | #define CORE_SPINLOCK_UNLOCKED 0 |
---|
| 67 | |
---|
| 68 | /** This indicates the lock is unavailable. */ |
---|
| 69 | #define CORE_SPINLOCK_LOCKED 1 |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * @brief Initialize the spinlock. |
---|
| 73 | * |
---|
| 74 | * This routine initializes the spinlock based on the parameters passed. |
---|
| 75 | * |
---|
| 76 | * @param[in] the_spinlock is the spinlock control block to initialize |
---|
| 77 | * @param[in] the_spinlock_attributes define the behavior of this instance |
---|
| 78 | */ |
---|
| 79 | void _CORE_spinlock_Initialize( |
---|
| 80 | CORE_spinlock_Control *the_spinlock, |
---|
| 81 | CORE_spinlock_Attributes *the_spinlock_attributes |
---|
| 82 | ); |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * @brief Wait for spinlock. |
---|
| 86 | * |
---|
| 87 | * This routine wait for the spinlock to be released. If the spinlock |
---|
| 88 | * is set to automatic and this is the appropriate thread, then it returns |
---|
| 89 | * immediately. Otherwise, the calling thread is blocked until the spinlock |
---|
| 90 | * is released. |
---|
| 91 | * |
---|
| 92 | * @param[in] the_spinlock is the spinlock to wait for |
---|
| 93 | * @param[in] wait is true if willing to wait |
---|
| 94 | * @param[in] timeout is the maximum number of ticks to spin (0 is forever) |
---|
| 95 | * |
---|
| 96 | * @retval A status is returned which indicates the success or failure of |
---|
| 97 | * this operation. |
---|
| 98 | */ |
---|
| 99 | CORE_spinlock_Status _CORE_spinlock_Wait( |
---|
| 100 | CORE_spinlock_Control *the_spinlock, |
---|
| 101 | bool wait, |
---|
| 102 | Watchdog_Interval timeout |
---|
| 103 | ); |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * @brief Manually release the spinlock. |
---|
| 107 | * |
---|
| 108 | * This routine manually releases the spinlock. All of the threads waiting |
---|
| 109 | * for the spinlock will be readied. |
---|
| 110 | * |
---|
| 111 | * @param[in] the_spinlock is the spinlock to surrender |
---|
| 112 | */ |
---|
| 113 | CORE_spinlock_Status _CORE_spinlock_Release( |
---|
| 114 | CORE_spinlock_Control *the_spinlock |
---|
| 115 | ); |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * This method is used to initialize core spinlock attributes. |
---|
| 119 | * |
---|
| 120 | * @param[in] the_attributes pointer to the attributes to initialize. |
---|
| 121 | */ |
---|
| 122 | RTEMS_INLINE_ROUTINE void _CORE_spinlock_Initialize_attributes( |
---|
| 123 | CORE_spinlock_Attributes *the_attributes |
---|
| 124 | ) |
---|
| 125 | { |
---|
| 126 | the_attributes->XXX = 0; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * This method is used to determine if the spinlock is available or not. |
---|
| 131 | * |
---|
| 132 | * @param[in] the_spinlock will be checked |
---|
| 133 | * |
---|
| 134 | * @return This method will return true if the spinlock is busy |
---|
| 135 | * and false otherwise. |
---|
| 136 | */ |
---|
| 137 | RTEMS_INLINE_ROUTINE bool _CORE_spinlock_Is_busy( |
---|
| 138 | CORE_spinlock_Control *the_spinlock |
---|
| 139 | ) |
---|
| 140 | { |
---|
| 141 | return (the_spinlock->users != 0); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** @} */ |
---|
| 145 | |
---|
| 146 | #ifdef __cplusplus |
---|
| 147 | } |
---|
| 148 | #endif |
---|
| 149 | |
---|
| 150 | #endif |
---|
| 151 | /* end of include file */ |
---|