17 #ifndef _RTEMS_SCORE_SMPLOCKTICKET_H 18 #define _RTEMS_SCORE_SMPLOCKTICKET_H 20 #include <rtems/score/cpuopts.h> 22 #if defined(RTEMS_SMP) 41 Atomic_Uint next_ticket;
42 Atomic_Uint now_serving;
43 } SMP_ticket_lock_Control;
48 #define SMP_TICKET_LOCK_INITIALIZER \ 50 ATOMIC_INITIALIZER_UINT( 0U ), \ 51 ATOMIC_INITIALIZER_UINT( 0U ) \ 61 static inline void _SMP_ticket_lock_Initialize(
62 SMP_ticket_lock_Control *lock
65 _Atomic_Init_uint( &lock->next_ticket, 0U );
66 _Atomic_Init_uint( &lock->now_serving, 0U );
76 static inline void _SMP_ticket_lock_Destroy( SMP_ticket_lock_Control *lock )
81 static inline void _SMP_ticket_lock_Do_acquire(
82 SMP_ticket_lock_Control *lock
83 #
if defined(RTEMS_PROFILING)
85 SMP_lock_Stats *stats,
86 SMP_lock_Stats_context *stats_context
90 unsigned int my_ticket;
91 unsigned int now_serving;
92 #if defined(RTEMS_PROFILING) 93 unsigned int initial_queue_length;
94 SMP_lock_Stats_acquire_context acquire_context;
96 _SMP_lock_Stats_acquire_begin( &acquire_context );
100 _Atomic_Fetch_add_uint( &lock->next_ticket, 1U, ATOMIC_ORDER_RELAXED );
102 #if defined(RTEMS_PROFILING) 104 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
105 initial_queue_length = my_ticket - now_serving;
107 if ( initial_queue_length > 0 ) {
112 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
113 }
while ( now_serving != my_ticket );
115 #if defined(RTEMS_PROFILING) 118 _SMP_lock_Stats_acquire_end(
138 #if defined(RTEMS_PROFILING) 139 #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \ 140 _SMP_ticket_lock_Do_acquire( lock, stats, stats_context ) 142 #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \ 143 _SMP_ticket_lock_Do_acquire( lock ) 146 static inline void _SMP_ticket_lock_Do_release(
147 SMP_ticket_lock_Control *lock
148 #
if defined(RTEMS_PROFILING)
150 const SMP_lock_Stats_context *stats_context
154 unsigned int current_ticket =
155 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_RELAXED );
156 unsigned int next_ticket = current_ticket + 1U;
158 #if defined(RTEMS_PROFILING) 159 _SMP_lock_Stats_release_update( stats_context );
162 _Atomic_Store_uint( &lock->now_serving, next_ticket, ATOMIC_ORDER_RELEASE );
171 #if defined(RTEMS_PROFILING) 172 #define _SMP_ticket_lock_Release( lock, stats_context ) \ 173 _SMP_ticket_lock_Do_release( lock, stats_context ) 175 #define _SMP_ticket_lock_Release( lock, stats_context ) \ 176 _SMP_ticket_lock_Do_release( lock )