37#ifndef _RTEMS_SCORE_SMPLOCKTICKET_H
38#define _RTEMS_SCORE_SMPLOCKTICKET_H
40#include <rtems/score/cpuopts.h>
61 Atomic_Uint next_ticket;
62 Atomic_Uint now_serving;
63} SMP_ticket_lock_Control;
68#define SMP_TICKET_LOCK_INITIALIZER \
70 ATOMIC_INITIALIZER_UINT( 0U ), \
71 ATOMIC_INITIALIZER_UINT( 0U ) \
81static inline void _SMP_ticket_lock_Initialize(
82 SMP_ticket_lock_Control *lock
85 _Atomic_Init_uint( &lock->next_ticket, 0U );
86 _Atomic_Init_uint( &lock->now_serving, 0U );
96static inline void _SMP_ticket_lock_Destroy( SMP_ticket_lock_Control *lock )
108static inline void _SMP_ticket_lock_Do_acquire(
109 SMP_ticket_lock_Control *lock
110#
if defined(RTEMS_PROFILING)
112 SMP_lock_Stats *stats,
113 SMP_lock_Stats_context *stats_context
117 unsigned int my_ticket;
118 unsigned int now_serving;
119#if defined(RTEMS_PROFILING)
120 unsigned int initial_queue_length;
121 SMP_lock_Stats_acquire_context acquire_context;
123 _SMP_lock_Stats_acquire_begin( &acquire_context );
127 _Atomic_Fetch_add_uint( &lock->next_ticket, 1U, ATOMIC_ORDER_RELAXED );
129#if defined(RTEMS_PROFILING)
131 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
132 initial_queue_length = my_ticket - now_serving;
134 if ( initial_queue_length > 0 ) {
139 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
140 }
while ( now_serving != my_ticket );
142#if defined(RTEMS_PROFILING)
145 _SMP_lock_Stats_acquire_end(
165#if defined(RTEMS_PROFILING)
166 #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \
167 _SMP_ticket_lock_Do_acquire( lock, stats, stats_context )
169 #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \
170 _SMP_ticket_lock_Do_acquire( lock )
179static inline void _SMP_ticket_lock_Do_release(
180 SMP_ticket_lock_Control *lock
181#
if defined(RTEMS_PROFILING)
183 const SMP_lock_Stats_context *stats_context
187 unsigned int current_ticket =
188 _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_RELAXED );
189 unsigned int next_ticket = current_ticket + 1U;
191#if defined(RTEMS_PROFILING)
192 _SMP_lock_Stats_release_update( stats_context );
195 _Atomic_Store_uint( &lock->now_serving, next_ticket, ATOMIC_ORDER_RELEASE );
204#if defined(RTEMS_PROFILING)
205 #define _SMP_ticket_lock_Release( lock, stats_context ) \
206 _SMP_ticket_lock_Do_release( lock, stats_context )
208 #define _SMP_ticket_lock_Release( lock, stats_context ) \
209 _SMP_ticket_lock_Do_release( lock )
This header file provides the interfaces of the Atomic Operations.
This header file provides the interfaces of the SMP Locks related to lock statistics.