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 |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
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 | */ |
---|
59 | CORE_SPINLOCK_UNAVAILABLE, |
---|
60 | /** This status indicates that the spinlock is not currently locked and thus |
---|
61 | * should not be released. |
---|
62 | */ |
---|
63 | CORE_SPINLOCK_NOT_LOCKED |
---|
64 | } CORE_spinlock_Status; |
---|
65 | |
---|
66 | /** This is a shorthand for the last status code. */ |
---|
67 | #define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_NOT_LOCKED |
---|
68 | |
---|
69 | /** This indicates the lock is available. */ |
---|
70 | #define CORE_SPINLOCK_UNLOCKED 0 |
---|
71 | |
---|
72 | /** This indicates the lock is unavailable. */ |
---|
73 | #define CORE_SPINLOCK_LOCKED 1 |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Initialize the spinlock. |
---|
77 | * |
---|
78 | * This routine initializes the spinlock based on the parameters passed. |
---|
79 | * |
---|
80 | * @param[in] the_spinlock is the spinlock control block to initialize |
---|
81 | * @param[in] the_spinlock_attributes define the behavior of this instance |
---|
82 | */ |
---|
83 | void _CORE_spinlock_Initialize( |
---|
84 | CORE_spinlock_Control *the_spinlock, |
---|
85 | CORE_spinlock_Attributes *the_spinlock_attributes |
---|
86 | ); |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief Wait for spinlock. |
---|
90 | * |
---|
91 | * This routine wait for the spinlock to be released. If the spinlock |
---|
92 | * is set to automatic and this is the appropriate thread, then it returns |
---|
93 | * immediately. Otherwise, the calling thread is blocked until the spinlock |
---|
94 | * is released. |
---|
95 | * |
---|
96 | * @param[in] the_spinlock is the spinlock to wait for |
---|
97 | * @param[in] wait is true if willing to wait |
---|
98 | * @param[in] timeout is the maximum number of ticks to spin (0 is forever) |
---|
99 | * |
---|
100 | * @retval A status is returned which indicates the success or failure of |
---|
101 | * this operation. |
---|
102 | */ |
---|
103 | CORE_spinlock_Status _CORE_spinlock_Wait( |
---|
104 | CORE_spinlock_Control *the_spinlock, |
---|
105 | bool wait, |
---|
106 | Watchdog_Interval timeout |
---|
107 | ); |
---|
108 | |
---|
109 | /** |
---|
110 | * @brief Manually release the spinlock. |
---|
111 | * |
---|
112 | * This routine manually releases the spinlock. All of the threads waiting |
---|
113 | * for the spinlock will be readied. |
---|
114 | * |
---|
115 | * @param[in] the_spinlock is the spinlock to surrender |
---|
116 | */ |
---|
117 | CORE_spinlock_Status _CORE_spinlock_Release( |
---|
118 | CORE_spinlock_Control *the_spinlock |
---|
119 | ); |
---|
120 | |
---|
121 | /** |
---|
122 | * This method is used to initialize core spinlock attributes. |
---|
123 | * |
---|
124 | * @param[in] the_attributes pointer to the attributes to initialize. |
---|
125 | */ |
---|
126 | RTEMS_INLINE_ROUTINE void _CORE_spinlock_Initialize_attributes( |
---|
127 | CORE_spinlock_Attributes *the_attributes |
---|
128 | ) |
---|
129 | { |
---|
130 | the_attributes->XXX = 0; |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * This method is used to determine if the spinlock is available or not. |
---|
135 | * |
---|
136 | * @param[in] the_spinlock will be checked |
---|
137 | * |
---|
138 | * @return This method will return true if the spinlock is busy |
---|
139 | * and false otherwise. |
---|
140 | */ |
---|
141 | RTEMS_INLINE_ROUTINE bool _CORE_spinlock_Is_busy( |
---|
142 | CORE_spinlock_Control *the_spinlock |
---|
143 | ) |
---|
144 | { |
---|
145 | return (the_spinlock->users != 0); |
---|
146 | } |
---|
147 | |
---|
148 | /** @} */ |
---|
149 | |
---|
150 | #ifdef __cplusplus |
---|
151 | } |
---|
152 | #endif |
---|
153 | |
---|
154 | #endif |
---|
155 | /* end of include file */ |
---|