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 )
130 static inline void _SMP_MCS_lock_Do_acquire(
131 SMP_MCS_lock_Control *lock,
133 #
if defined(RTEMS_PROFILING)
135 SMP_lock_Stats *stats
139 SMP_MCS_lock_Context *previous;
140 #if defined(RTEMS_PROFILING) 141 SMP_lock_Stats_acquire_context acquire_context;
143 _SMP_lock_Stats_acquire_begin( &acquire_context );
147 _Atomic_Store_uintptr( &
context->next.atomic, 0, ATOMIC_ORDER_RELAXED );
148 _Atomic_Store_uint( &
context->locked, 1, ATOMIC_ORDER_RELAXED );
150 previous = (SMP_MCS_lock_Context *) _Atomic_Exchange_uintptr(
156 if ( previous !=
NULL ) {
159 _Atomic_Store_uintptr(
160 &previous->next.atomic,
166 locked = _Atomic_Load_uint( &
context->locked, ATOMIC_ORDER_ACQUIRE );
167 }
while ( locked != 0 );
170 #if defined(RTEMS_PROFILING) 171 _SMP_lock_Stats_acquire_end(
191 #if defined(RTEMS_PROFILING) 192 #define _SMP_MCS_lock_Acquire( lock, context, stats ) \ 193 _SMP_MCS_lock_Do_acquire( lock, context, stats ) 195 #define _SMP_MCS_lock_Acquire( lock, context, stats ) \ 196 _SMP_MCS_lock_Do_acquire( lock, context ) 205 static inline void _SMP_MCS_lock_Release(
206 SMP_MCS_lock_Control *lock,
210 SMP_MCS_lock_Context *next;
212 next = (SMP_MCS_lock_Context *) _Atomic_Load_uintptr(
213 &context->next.atomic,
217 if ( next ==
NULL ) {
221 expected = (uintptr_t) context;
222 success = _Atomic_Compare_exchange_uintptr(
226 ATOMIC_ORDER_RELEASE,
231 #if defined(RTEMS_PROFILING) 232 _SMP_lock_Stats_release_update( &context->Stats_context );
239 next = (SMP_MCS_lock_Context *) _Atomic_Load_uintptr(
240 &context->next.atomic,
243 }
while ( next ==
NULL );
246 #if defined(RTEMS_PROFILING) 247 next->queue_length = context->queue_length + 1;
248 _SMP_lock_Stats_release_update( &context->Stats_context );
251 _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