1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ScoreSMPLock |
---|
5 | * |
---|
6 | * @brief SMP Lock API |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * Copyright (c) 2013 embedded brains GmbH |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_SCORE_SMPLOCK_H |
---|
21 | #define _RTEMS_SCORE_SMPLOCK_H |
---|
22 | |
---|
23 | #include <rtems/score/cpuopts.h> |
---|
24 | |
---|
25 | #if defined( RTEMS_SMP ) |
---|
26 | |
---|
27 | #include <rtems/score/cpusmplock.h> |
---|
28 | #include <rtems/score/isr.h> |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif /* __cplusplus */ |
---|
33 | |
---|
34 | /** |
---|
35 | * @defgroup ScoreSMPLock SMP Locks |
---|
36 | * |
---|
37 | * @ingroup Score |
---|
38 | * |
---|
39 | * The SMP lock implementation is architecture dependent. The implementation |
---|
40 | * should provide fairness in case of concurrent lock attempts. A ticket lock |
---|
41 | * is probably the most likely implementation. |
---|
42 | * |
---|
43 | * This SMP lock API has a flaw. It does not provide the ability to use a |
---|
44 | * local context for acquire and release pairs. Such a context is necessary to |
---|
45 | * implement for example the Mellor-Crummey and Scott (MCS) locks. The SMP |
---|
46 | * lock is currently used in _Thread_Disable_dispatch() and |
---|
47 | * _Thread_Enable_dispatch() and makes them to a giant lock acquire and |
---|
48 | * release. Since these functions do not pass state information via a local |
---|
49 | * context there is currently no use case for such a feature. |
---|
50 | * |
---|
51 | * @{ |
---|
52 | */ |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief SMP lock control. |
---|
56 | * |
---|
57 | * This is an opaque type. The SMP lock implementation is architecture |
---|
58 | * dependent. |
---|
59 | */ |
---|
60 | typedef CPU_SMP_lock_Control SMP_lock_Control; |
---|
61 | |
---|
62 | /** |
---|
63 | * @brief SMP lock control initializer for static initialization. |
---|
64 | */ |
---|
65 | #define SMP_LOCK_INITIALIZER CPU_SMP_LOCK_INITIALIZER |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief Initializes a SMP lock control. |
---|
69 | * |
---|
70 | * Concurrent initialization leads to unpredictable results. |
---|
71 | * |
---|
72 | * @param[out] lock The SMP lock control. |
---|
73 | */ |
---|
74 | static inline void _SMP_lock_Initialize( SMP_lock_Control *lock ) |
---|
75 | { |
---|
76 | _CPU_SMP_lock_Initialize( lock ); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * @brief Acquires a SMP lock. |
---|
81 | * |
---|
82 | * This function will not disable interrupts. The caller must ensure that the |
---|
83 | * current thread of execution is not interrupted indefinite once it obtained |
---|
84 | * the SMP lock. |
---|
85 | * |
---|
86 | * @param[in/out] lock The SMP lock control. |
---|
87 | */ |
---|
88 | static inline void _SMP_lock_Acquire( SMP_lock_Control *lock ) |
---|
89 | { |
---|
90 | _CPU_SMP_lock_Acquire( lock ); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief Releases a SMP lock. |
---|
95 | * |
---|
96 | * @param[in/out] lock The SMP lock control. |
---|
97 | */ |
---|
98 | static inline void _SMP_lock_Release( SMP_lock_Control *lock ) |
---|
99 | { |
---|
100 | _CPU_SMP_lock_Release( lock ); |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * @brief Disables interrupts and acquires the SMP lock. |
---|
105 | * |
---|
106 | * @param[in/out] lock The SMP lock control. |
---|
107 | * @param[out] isr_cookie The ISR cookie. |
---|
108 | */ |
---|
109 | #define _SMP_lock_ISR_disable_and_acquire( lock, isr_cookie ) \ |
---|
110 | _CPU_SMP_lock_ISR_disable_and_acquire( lock, isr_cookie ) |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief Releases the SMP lock and enables interrupts. |
---|
114 | * |
---|
115 | * @param[in/out] lock The SMP lock control. |
---|
116 | * @param[in] isr_cookie The ISR cookie. |
---|
117 | */ |
---|
118 | #define _SMP_lock_Release_and_ISR_enable( lock, isr_cookie ) \ |
---|
119 | _CPU_SMP_lock_Release_and_ISR_enable( lock, isr_cookie ) |
---|
120 | |
---|
121 | /**@}*/ |
---|
122 | |
---|
123 | #ifdef __cplusplus |
---|
124 | } |
---|
125 | #endif /* __cplusplus */ |
---|
126 | |
---|
127 | #endif /* defined( RTEMS_SMP ) */ |
---|
128 | |
---|
129 | #endif /* _RTEMS_SCORE_SMPLOCK_H */ |
---|