1 | /** |
---|
2 | * @file rtems/score/smplock.h |
---|
3 | * |
---|
4 | * This include file defines the interface for atomic locks |
---|
5 | * which can be used in multiprocessor configurations. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef _RTEMS_LOCK_H |
---|
18 | #define _RTEMS_LOCK_H |
---|
19 | |
---|
20 | #include <rtems/score/isr.h> |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup RTEMS Lock Interface |
---|
24 | * |
---|
25 | * @ingroup Score |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /**@{*/ |
---|
30 | |
---|
31 | #ifdef __cplusplus |
---|
32 | extern "C" { |
---|
33 | #endif |
---|
34 | |
---|
35 | /** |
---|
36 | * This type is used to lock elements for atomic access. |
---|
37 | * This spinlock is a simple non-nesting spinlock, and |
---|
38 | * may be used for short non-nesting accesses. |
---|
39 | */ |
---|
40 | typedef uint32_t SMP_lock_spinlock_simple_Control; |
---|
41 | |
---|
42 | /** |
---|
43 | * This type is used to lock elements for atomic access. |
---|
44 | * This spinlock supports nesting, but is slightly more |
---|
45 | * complicated to use. Please see the descriptions of |
---|
46 | * obtain and release prior to using in order to understand |
---|
47 | * the callers responsibilty of managing short interupt disable |
---|
48 | * times. |
---|
49 | */ |
---|
50 | typedef struct { |
---|
51 | SMP_lock_spinlock_simple_Control lock; |
---|
52 | uint32_t count; |
---|
53 | int cpu_id; |
---|
54 | } SMP_lock_spinlock_nested_Control; |
---|
55 | |
---|
56 | /** |
---|
57 | * @brief Initialize a Lock |
---|
58 | * |
---|
59 | * This method is used to initialize the lock at @a lock. |
---|
60 | * |
---|
61 | * @param [in] lock is the address of the lock to obtain. |
---|
62 | */ |
---|
63 | void _SMP_lock_spinlock_simple_Initialize( |
---|
64 | SMP_lock_spinlock_simple_Control *lock |
---|
65 | ); |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief Obtain a Lock |
---|
69 | * |
---|
70 | * This method is used to obtain the lock at @a lock. |
---|
71 | * |
---|
72 | * @param [in] lock is the address of the lock to obtain. |
---|
73 | * |
---|
74 | * @return This method returns with processor interrupts disabled. |
---|
75 | * The previous level is returned. |
---|
76 | */ |
---|
77 | ISR_Level _SMP_lock_spinlock_simple_Obtain( |
---|
78 | SMP_lock_spinlock_simple_Control *lock |
---|
79 | ); |
---|
80 | |
---|
81 | /** |
---|
82 | * @brief Release a Lock |
---|
83 | * |
---|
84 | * This method is used to release the lock at @a lock. |
---|
85 | * |
---|
86 | * @param [in] lock is the address of the lock to obtain. |
---|
87 | */ |
---|
88 | void _SMP_lock_spinlock_simple_Release( |
---|
89 | SMP_lock_spinlock_simple_Control *lock, |
---|
90 | ISR_Level level |
---|
91 | ); |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief Initialize a Lock |
---|
95 | * |
---|
96 | * This method is used to initialize the lock at @a lock. |
---|
97 | * |
---|
98 | * @param [in] lock is the address of the lock to obtain. |
---|
99 | */ |
---|
100 | void _SMP_lock_spinlock_nested_Initialize( |
---|
101 | SMP_lock_spinlock_nested_Control *lock |
---|
102 | ); |
---|
103 | |
---|
104 | /** |
---|
105 | * @brief Obtain a Lock |
---|
106 | * |
---|
107 | * This method is used to obtain the lock at @a lock. ISR's are |
---|
108 | * disabled when this routine returns and it is the callers responsibility |
---|
109 | * to either: |
---|
110 | * |
---|
111 | * # Do something very short and then call |
---|
112 | * _SMP_lock_spinlock_nested_Release or |
---|
113 | * # Do something very sort, call isr enable, then when ready |
---|
114 | * call isr_disable and _SMP_lock_spinlock_nested_Release |
---|
115 | * |
---|
116 | * @param [in] lock is the address of the lock to obtain. |
---|
117 | * |
---|
118 | * @return This method returns with processor interrupts disabled. |
---|
119 | * The previous level is returned. |
---|
120 | */ |
---|
121 | ISR_Level _SMP_lock_spinlock_nested_Obtain( |
---|
122 | SMP_lock_spinlock_nested_Control *lock |
---|
123 | ); |
---|
124 | |
---|
125 | /** |
---|
126 | * @brief Release a Lock |
---|
127 | * |
---|
128 | * This method is used to release the lock at @a lock. |
---|
129 | * |
---|
130 | * @note ISR's are reenabled by this method and are expected to be |
---|
131 | * disabled upon entry to the method. |
---|
132 | * |
---|
133 | * @param [in] lock is the address of the lock to obtain. |
---|
134 | */ |
---|
135 | void _SMP_lock_spinlock_nested_Release( |
---|
136 | SMP_lock_spinlock_nested_Control *lock, |
---|
137 | ISR_Level level |
---|
138 | ); |
---|
139 | |
---|
140 | #ifdef __cplusplus |
---|
141 | } |
---|
142 | #endif |
---|
143 | |
---|
144 | /**@}*/ |
---|
145 | |
---|
146 | #endif |
---|
147 | /* end of include file */ |
---|