RTEMS
Files | Classes | Macros | Typedefs | Functions
SMP Locks

The SMP lock provides mutual exclusion for SMP systems at the lowest level. More...

Files

file  smplock.h
 SMP Lock API.
 
file  smplockmcs.h
 SMP Lock API.
 
file  smplockseq.h
 SMP Lock API.
 
file  smplockstats.h
 SMP Lock API.
 
file  smplockticket.h
 SMP Lock API.
 

Classes

struct  SMP_lock_Control
 SMP lock control. More...
 
struct  SMP_lock_Context
 Local SMP lock context for acquire and release pairs. More...
 
struct  SMP_MCS_lock_Context
 SMP Mellor-Crummey and Scott (MCS) lock context. More...
 
struct  SMP_MCS_lock_Control
 SMP Mellor-Crummey and Scott (MCS) lock control. More...
 
struct  SMP_sequence_lock_Control
 SMP sequence lock control. More...
 
struct  SMP_ticket_lock_Control
 SMP ticket lock control. More...
 

Macros

#define SMP_LOCK_INITIALIZER(name)   { SMP_TICKET_LOCK_INITIALIZER }
 SMP lock control initializer for static initialization.
 
#define _SMP_lock_Initialize(lock, name)   _SMP_lock_Initialize_inline( lock, name )
 Initializes an SMP lock. More...
 
#define _SMP_lock_Destroy(lock)   _SMP_lock_Destroy_inline( lock )
 Destroys an SMP lock. More...
 
#define _SMP_lock_Release(lock, context)   _SMP_lock_Release_inline( lock, context )
 Releases an SMP lock. More...
 
#define _SMP_lock_Release_and_ISR_enable(lock, context)   _SMP_lock_Release_and_ISR_enable_inline( lock, context )
 Releases the SMP lock and enables interrupts. More...
 
#define SMP_MCS_LOCK_INITIALIZER   { { ATOMIC_INITIALIZER_UINTPTR( 0 ) } }
 SMP MCS lock control initializer for static initialization.
 
#define _SMP_MCS_lock_Acquire(lock, context, stats)   _SMP_MCS_lock_Do_acquire( lock, context )
 Acquires an SMP MCS lock. More...
 
#define SMP_SEQUENCE_LOCK_INITIALIZER   { ATOMIC_INITIALIZER_UINT( 0 ) }
 SMP sequence lock control initializer for static initialization.
 
#define _SMP_lock_Stats_initialize(stats, name)   do { } while ( 0 )
 
#define _SMP_lock_Stats_destroy(stats)   do { } while ( 0 )
 
#define SMP_TICKET_LOCK_INITIALIZER
 SMP ticket lock control initializer for static initialization. More...
 
#define _SMP_ticket_lock_Acquire(lock, stats, stats_context)   _SMP_ticket_lock_Do_acquire( lock )
 Acquires an SMP ticket lock. More...
 
#define _SMP_ticket_lock_Release(lock, stats_context)   _SMP_ticket_lock_Do_release( lock )
 Releases an SMP ticket lock. More...
 

Typedefs

typedef struct SMP_MCS_lock_Context SMP_MCS_lock_Context
 SMP Mellor-Crummey and Scott (MCS) lock context.
 

Functions

static void _SMP_lock_Initialize_inline (SMP_lock_Control *lock, const char *name)
 Initializes the SMP lock with the given name. More...
 
static void _SMP_lock_Destroy_inline (SMP_lock_Control *lock)
 Destroys the SMP lock. More...
 
static void _SMP_lock_Set_name (SMP_lock_Control *lock, const char *name)
 Sets the name of an SMP lock. More...
 
static void _SMP_lock_Acquire_inline (SMP_lock_Control *lock, SMP_lock_Context *context)
 Gets my index. More...
 
void _SMP_lock_Acquire (SMP_lock_Control *lock, SMP_lock_Context *context)
 Acquires an SMP lock. More...
 
static void _SMP_lock_Release_inline (SMP_lock_Control *lock, SMP_lock_Context *context)
 Releases an SMP lock. More...
 
static void _SMP_lock_ISR_disable_and_acquire_inline (SMP_lock_Control *lock, SMP_lock_Context *context)
 Disables interrupts and acquires the SMP lock. More...
 
void _SMP_lock_ISR_disable_and_acquire (SMP_lock_Control *lock, SMP_lock_Context *context)
 Disables interrupts and acquires the SMP lock. More...
 
static void _SMP_lock_Release_and_ISR_enable_inline (SMP_lock_Control *lock, SMP_lock_Context *context)
 Releases the SMP lock and enables interrupts. More...
 
static void _SMP_MCS_lock_Initialize (SMP_MCS_lock_Control *lock)
 Initializes the SMP MCS lock. More...
 
static void _SMP_MCS_lock_Destroy (SMP_MCS_lock_Control *lock)
 Destroys the SMP MCS lock. More...
 
static void _SMP_MCS_lock_Do_acquire (SMP_MCS_lock_Control *lock, SMP_MCS_lock_Context *context)
 Acquires the SMP MCS lock. More...
 
static void _SMP_MCS_lock_Release (SMP_MCS_lock_Control *lock, SMP_MCS_lock_Context *context)
 Releases an SMP MCS lock. More...
 
static void _SMP_sequence_lock_Initialize (SMP_sequence_lock_Control *lock)
 Initializes an SMP sequence lock. More...
 
static void _SMP_sequence_lock_Destroy (SMP_sequence_lock_Control *lock)
 Destroys an SMP sequence lock. More...
 
static unsigned int _SMP_sequence_lock_Write_begin (SMP_sequence_lock_Control *lock)
 Begins an SMP sequence lock write operation. More...
 
static void _SMP_sequence_lock_Write_end (SMP_sequence_lock_Control *lock, unsigned int seq)
 Ends an SMP sequence lock write operation. More...
 
static unsigned int _SMP_sequence_lock_Read_begin (const SMP_sequence_lock_Control *lock)
 Begins an SMP sequence lock read operation. More...
 
static bool _SMP_sequence_lock_Read_retry (SMP_sequence_lock_Control *lock, unsigned int seq)
 Ends an SMP sequence lock read operation and indicates if a retry is necessary. More...
 
static void _SMP_ticket_lock_Initialize (SMP_ticket_lock_Control *lock)
 Initializes the SMP ticket lock. More...
 
static void _SMP_ticket_lock_Destroy (SMP_ticket_lock_Control *lock)
 Destroys the SMP ticket lock. More...
 
static void _SMP_ticket_lock_Do_acquire (SMP_ticket_lock_Control *lock)
 Acquires the SMP ticket lock. More...
 
static void _SMP_ticket_lock_Do_release (SMP_ticket_lock_Control *lock)
 Releases the SMP ticket lock. More...
 

Detailed Description

The SMP lock provides mutual exclusion for SMP systems at the lowest level.

The SMP lock is implemented as a ticket lock. This provides fairness in case of concurrent lock attempts.

This SMP lock API uses a local context for acquire and release pairs. Such a context may be used to implement for example the Mellor-Crummey and Scott (MCS) locks in the future.

Macro Definition Documentation

◆ _SMP_lock_Destroy

#define _SMP_lock_Destroy (   lock)    _SMP_lock_Destroy_inline( lock )

Destroys an SMP lock.

Concurrent destruction leads to unpredictable results.

Parameters
[in,out]lockThe SMP lock control.

Definition at line 185 of file smplock.h.

◆ _SMP_lock_Initialize

#define _SMP_lock_Initialize (   lock,
  name 
)    _SMP_lock_Initialize_inline( lock, name )

Initializes an SMP lock.

Concurrent initialization leads to unpredictable results.

Parameters
[in,out]lockThe SMP lock control.
nameThe name for the SMP lock statistics. This name must be persistent throughout the life time of this statistics block.

Definition at line 160 of file smplock.h.

◆ _SMP_lock_Release

#define _SMP_lock_Release (   lock,
  context 
)    _SMP_lock_Release_inline( lock, context )

Releases an SMP lock.

Parameters
[in,out]lockThe SMP lock control.
[in,out]contextThe local SMP lock context for an acquire and release pair.

Definition at line 304 of file smplock.h.

◆ _SMP_lock_Release_and_ISR_enable

#define _SMP_lock_Release_and_ISR_enable (   lock,
  context 
)    _SMP_lock_Release_and_ISR_enable_inline( lock, context )

Releases the SMP lock and enables interrupts.

Parameters
[in,out]lockThe SMP lock control.
[in,out]contextThe local SMP lock context for an acquire and release pair.

Definition at line 363 of file smplock.h.

◆ _SMP_MCS_lock_Acquire

#define _SMP_MCS_lock_Acquire (   lock,
  context,
  stats 
)    _SMP_MCS_lock_Do_acquire( lock, context )

Acquires an SMP MCS lock.

This function will not disable interrupts. The caller must ensure that the current thread of execution is not interrupted indefinite once it obtained the SMP MCS lock.

Parameters
lockThe SMP MCS lock control.
contextThe SMP MCS lock context.
statsThe SMP lock statistics.

Definition at line 202 of file smplockmcs.h.

◆ _SMP_ticket_lock_Acquire

#define _SMP_ticket_lock_Acquire (   lock,
  stats,
  stats_context 
)    _SMP_ticket_lock_Do_acquire( lock )

Acquires an SMP ticket lock.

This function will not disable interrupts. The caller must ensure that the current thread of execution is not interrupted indefinite once it obtained the SMP ticket lock.

Parameters
[in]lockThe SMP ticket lock control.
[in]statsThe SMP lock statistics.
[out]stats_contextThe SMP lock statistics context.

Definition at line 149 of file smplockticket.h.

◆ _SMP_ticket_lock_Release

#define _SMP_ticket_lock_Release (   lock,
  stats_context 
)    _SMP_ticket_lock_Do_release( lock )

Releases an SMP ticket lock.

Parameters
[in]lockThe SMP ticket lock control.
[in]stats_contextThe SMP lock statistics context.

Definition at line 188 of file smplockticket.h.

◆ SMP_TICKET_LOCK_INITIALIZER

#define SMP_TICKET_LOCK_INITIALIZER
Value:
{ \
ATOMIC_INITIALIZER_UINT( 0U ), \
ATOMIC_INITIALIZER_UINT( 0U ) \
}

SMP ticket lock control initializer for static initialization.

Definition at line 48 of file smplockticket.h.

Function Documentation

◆ _SMP_lock_Acquire()

void _SMP_lock_Acquire ( SMP_lock_Control lock,
SMP_lock_Context context 
)

Acquires an SMP lock.

This function will not disable interrupts. The caller must ensure that the current thread of execution is not interrupted indefinite once it obtained the SMP lock.

Parameters
[in,out]lockThe SMP lock control.
[in,out]contextThe local SMP lock context for an acquire and release pair.

Definition at line 36 of file smplock.c.

◆ _SMP_lock_Acquire_inline()

static void _SMP_lock_Acquire_inline ( SMP_lock_Control lock,
SMP_lock_Context context 
)
inlinestatic

Gets my index.

Returns
The current processor index + 1. Acquires the lock inline.
Parameters
[in,out]lockThe lock to acquire.
[in,out]contextThe lock context.

Definition at line 230 of file smplock.h.

◆ _SMP_lock_Destroy_inline()

static void _SMP_lock_Destroy_inline ( SMP_lock_Control lock)
inlinestatic

Destroys the SMP lock.

Parameters
[in,out]lockThe lock to destroy.

Definition at line 169 of file smplock.h.

◆ _SMP_lock_Initialize_inline()

static void _SMP_lock_Initialize_inline ( SMP_lock_Control lock,
const char *  name 
)
inlinestatic

Initializes the SMP lock with the given name.

Parameters
[in,out]lockThe lock to initialize.

Definition at line 129 of file smplock.h.

◆ _SMP_lock_ISR_disable_and_acquire()

void _SMP_lock_ISR_disable_and_acquire ( SMP_lock_Control lock,
SMP_lock_Context context 
)

Disables interrupts and acquires the SMP lock.

Parameters
[in,out]lockThe SMP lock control.
[in,out]contextThe local SMP lock context for an acquire and release pair.

Definition at line 54 of file smplock.c.

◆ _SMP_lock_ISR_disable_and_acquire_inline()

static void _SMP_lock_ISR_disable_and_acquire_inline ( SMP_lock_Control lock,
SMP_lock_Context context 
)
inlinestatic

Disables interrupts and acquires the SMP lock.

Parameters
[in,out]lockThe lock to acquire.
[in,out]contextThe lock context.

Definition at line 314 of file smplock.h.

◆ _SMP_lock_Release_and_ISR_enable_inline()

static void _SMP_lock_Release_and_ISR_enable_inline ( SMP_lock_Control lock,
SMP_lock_Context context 
)
inlinestatic

Releases the SMP lock and enables interrupts.

Parameters
[in,out]lockThe SMP lock to release.
[in,out]contextThe lock context.

Definition at line 341 of file smplock.h.

◆ _SMP_lock_Release_inline()

static void _SMP_lock_Release_inline ( SMP_lock_Control lock,
SMP_lock_Context context 
)
inlinestatic

Releases an SMP lock.

Parameters
[in,out]lockThe lock to release.
[in,out]contextThe lock context.

Definition at line 272 of file smplock.h.

◆ _SMP_lock_Set_name()

static void _SMP_lock_Set_name ( SMP_lock_Control lock,
const char *  name 
)
inlinestatic

Sets the name of an SMP lock.

Parameters
[out]lockThe SMP lock control.
nameThe name for the SMP lock statistics. This name must be persistent throughout the life time of this statistics block.

Definition at line 196 of file smplock.h.

◆ _SMP_MCS_lock_Destroy()

static void _SMP_MCS_lock_Destroy ( SMP_MCS_lock_Control lock)
inlinestatic

Destroys the SMP MCS lock.

Concurrent destruction leads to unpredictable results.

Parameters
[out]lockThe SMP MCS lock control.

Definition at line 125 of file smplockmcs.h.

◆ _SMP_MCS_lock_Do_acquire()

static void _SMP_MCS_lock_Do_acquire ( SMP_MCS_lock_Control lock,
SMP_MCS_lock_Context context 
)
inlinestatic

Acquires the SMP MCS lock.

Parameters
[in,out]lockThe lock to acquire.
[in,out]contextThe lock context.
statsthe SMP lock statistics.

Definition at line 137 of file smplockmcs.h.

◆ _SMP_MCS_lock_Initialize()

static void _SMP_MCS_lock_Initialize ( SMP_MCS_lock_Control lock)
inlinestatic

Initializes the SMP MCS lock.

Concurrent initialization leads to unpredictable results.

Parameters
[in,out]lockThe SMP MCS lock control.

Definition at line 113 of file smplockmcs.h.

◆ _SMP_MCS_lock_Release()

static void _SMP_MCS_lock_Release ( SMP_MCS_lock_Control lock,
SMP_MCS_lock_Context context 
)
inlinestatic

Releases an SMP MCS lock.

Parameters
[in,out]lockThe SMP MCS lock control.
[in,out]contextThe SMP MCS lock context.

Definition at line 212 of file smplockmcs.h.

◆ _SMP_sequence_lock_Destroy()

static void _SMP_sequence_lock_Destroy ( SMP_sequence_lock_Control lock)
inlinestatic

Destroys an SMP sequence lock.

Concurrent destruction leads to unpredictable results.

Parameters
lockThe SMP sequence lock control.

Definition at line 83 of file smplockseq.h.

◆ _SMP_sequence_lock_Initialize()

static void _SMP_sequence_lock_Initialize ( SMP_sequence_lock_Control lock)
inlinestatic

Initializes an SMP sequence lock.

Concurrent initialization leads to unpredictable results.

Parameters
[out]lockThe SMP sequence lock control.

Definition at line 71 of file smplockseq.h.

◆ _SMP_sequence_lock_Read_begin()

static unsigned int _SMP_sequence_lock_Read_begin ( const SMP_sequence_lock_Control lock)
inlinestatic

Begins an SMP sequence lock read operation.

This function will not disable interrupts.

Parameters
[out]lockThe SMP sequence lock control.
Returns
The current sequence number.

Definition at line 139 of file smplockseq.h.

◆ _SMP_sequence_lock_Read_retry()

static bool _SMP_sequence_lock_Read_retry ( SMP_sequence_lock_Control lock,
unsigned int  seq 
)
inlinestatic

Ends an SMP sequence lock read operation and indicates if a retry is necessary.

Parameters
[in,out]lockThe SMP sequence lock control.
seqThe sequence number returned by _SMP_sequence_lock_Read_begin().
Return values
trueThe read operation must be retried with a call to _SMP_sequence_lock_Read_begin().
falseThe read operation need not be retried.

Definition at line 157 of file smplockseq.h.

◆ _SMP_sequence_lock_Write_begin()

static unsigned int _SMP_sequence_lock_Write_begin ( SMP_sequence_lock_Control lock)
inlinestatic

Begins an SMP sequence lock write operation.

This function will not disable interrupts. The caller must ensure that the current thread of execution is not interrupted indefinite since this would starve readers.

Parameters
[out]lockThe SMP sequence lock control.
Returns
The current sequence number.

Definition at line 99 of file smplockseq.h.

◆ _SMP_sequence_lock_Write_end()

static void _SMP_sequence_lock_Write_end ( SMP_sequence_lock_Control lock,
unsigned int  seq 
)
inlinestatic

Ends an SMP sequence lock write operation.

Parameters
[out]lockThe SMP sequence lock control.
seqThe sequence number returned by _SMP_sequence_lock_Write_begin().

Definition at line 122 of file smplockseq.h.

◆ _SMP_ticket_lock_Destroy()

static void _SMP_ticket_lock_Destroy ( SMP_ticket_lock_Control lock)
inlinestatic

Destroys the SMP ticket lock.

Concurrent destruction leads to unpredictable results.

Parameters
lockThe SMP ticket lock control.

Definition at line 76 of file smplockticket.h.

◆ _SMP_ticket_lock_Do_acquire()

static void _SMP_ticket_lock_Do_acquire ( SMP_ticket_lock_Control lock)
inlinestatic

Acquires the SMP ticket lock.

Parameters
[in,out]lockThe lock to acquire.
statsThe SMP lock statistics.
[out]stats_contextThe context for the statistics.

Definition at line 88 of file smplockticket.h.

◆ _SMP_ticket_lock_Do_release()

static void _SMP_ticket_lock_Do_release ( SMP_ticket_lock_Control lock)
inlinestatic

Releases the SMP ticket lock.

Parameters
[in,out]lockThe SMP ticket lock to release.
[out]stats_contextThe SMP lock statistics context.

Definition at line 159 of file smplockticket.h.

◆ _SMP_ticket_lock_Initialize()

static void _SMP_ticket_lock_Initialize ( SMP_ticket_lock_Control lock)
inlinestatic

Initializes the SMP ticket lock.

Concurrent initialization leads to unpredictable results.

Parameters
[in,out]lockThe SMP ticket lock control.

Definition at line 61 of file smplockticket.h.