17 #ifndef _RTEMS_SCORE_SMPLOCKMCS_H 18 #define _RTEMS_SCORE_SMPLOCKMCS_H 20 #include <rtems/score/cpuopts.h> 22 #if defined(RTEMS_SMP) 40 typedef struct SMP_MCS_lock_Context {
48 Atomic_Uintptr atomic;
55 struct SMP_MCS_lock_Context *normal;
68 #if defined(RTEMS_PROFILING) 69 SMP_lock_Stats_context Stats_context;
71 unsigned int queue_length;
73 } SMP_MCS_lock_Context;
90 Atomic_Uintptr atomic;
97 struct SMP_MCS_lock_Context *normal;
99 } SMP_MCS_lock_Control;
104 #define SMP_MCS_LOCK_INITIALIZER { { ATOMIC_INITIALIZER_UINTPTR( 0 ) } } 113 static inline void _SMP_MCS_lock_Initialize( SMP_MCS_lock_Control *lock )
115 _Atomic_Init_uintptr( &lock->queue.atomic, 0 );
125 static inline void _SMP_MCS_lock_Destroy( SMP_MCS_lock_Control *lock )
137 static inline void _SMP_MCS_lock_Do_acquire(
138 SMP_MCS_lock_Control *lock,
140 #
if defined(RTEMS_PROFILING)
142 SMP_lock_Stats *stats
146 SMP_MCS_lock_Context *previous;
147 #if defined(RTEMS_PROFILING) 148 SMP_lock_Stats_acquire_context acquire_context;
150 _SMP_lock_Stats_acquire_begin( &acquire_context );
154 _Atomic_Store_uintptr( &
context->next.atomic, 0, ATOMIC_ORDER_RELAXED );
155 _Atomic_Store_uint( &
context->locked, 1, ATOMIC_ORDER_RELAXED );
157 previous = (SMP_MCS_lock_Context *) _Atomic_Exchange_uintptr(
163 if ( previous !=
NULL ) {
166 _Atomic_Store_uintptr(
167 &previous->next.atomic,
173 locked = _Atomic_Load_uint( &
context->locked, ATOMIC_ORDER_ACQUIRE );
174 }
while ( locked != 0 );
177 #if defined(RTEMS_PROFILING) 178 _SMP_lock_Stats_acquire_end(
198 #if defined(RTEMS_PROFILING) 199 #define _SMP_MCS_lock_Acquire( lock, context, stats ) \ 200 _SMP_MCS_lock_Do_acquire( lock, context, stats ) 202 #define _SMP_MCS_lock_Acquire( lock, context, stats ) \ 203 _SMP_MCS_lock_Do_acquire( lock, context ) 212 static inline void _SMP_MCS_lock_Release(
213 SMP_MCS_lock_Control *lock,
217 SMP_MCS_lock_Context *next;
219 next = (SMP_MCS_lock_Context *) _Atomic_Load_uintptr(
224 if ( next ==
NULL ) {
228 expected = (uintptr_t)
context;
229 success = _Atomic_Compare_exchange_uintptr(
233 ATOMIC_ORDER_RELEASE,
238 #if defined(RTEMS_PROFILING) 239 _SMP_lock_Stats_release_update( &
context->Stats_context );
246 next = (SMP_MCS_lock_Context *) _Atomic_Load_uintptr(
250 }
while ( next ==
NULL );
253 #if defined(RTEMS_PROFILING) 254 next->queue_length =
context->queue_length + 1;
255 _SMP_lock_Stats_release_update( &
context->Stats_context );
258 _Atomic_Store_uint( &next->locked, 0, ATOMIC_ORDER_RELEASE );
unsigned context
Definition: tlb.h:108
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77