Loading...
Searching...
No Matches
critical_section

Critical Section API for short-lived mutual exclusion safe for IRQ and multi-core. More...

Data Structures

struct  critical_section
 Critical section instance. More...
 

Typedefs

typedef struct __packed_aligned critical_section critical_section_t
 Critical section instance.
 

Functions

void critical_section_init (critical_section_t *crit_sec)
 Initialise a critical_section structure allowing the system to assign a spin lock number.
 
void critical_section_init_with_lock_num (critical_section_t *crit_sec, uint lock_num)
 Initialise a critical_section structure assigning a specific spin lock number.
 
static __force_inline void critical_section_enter_blocking (critical_section_t *crit_sec)
 Enter a critical_section.
 
static __force_inline void critical_section_exit (critical_section_t *crit_sec)
 Release a critical_section.
 
void critical_section_deinit (critical_section_t *crit_sec)
 De-Initialise a critical_section created by the critical_section_init method.
 
static bool critical_section_is_initialized (critical_section_t *crit_sec)
 Test whether a critical_section has been initialized.
 

Detailed Description

Critical Section API for short-lived mutual exclusion safe for IRQ and multi-core.

A critical section is non-reentrant, and provides mutual exclusion using a spin-lock to prevent access from the other core, and from (higher priority) interrupts on the same core. It does the former using a spin lock and the latter by disabling interrupts on the calling core.

Because interrupts are disabled when a critical_section is owned, uses of the critical_section should be as short as possible.

Typedef Documentation

◆ critical_section_t

typedef struct __packed_aligned critical_section critical_section_t

Critical section instance.

Structure holding the state for a single critical section, including the associated spin lock and the saved interrupt state.

Function Documentation

◆ critical_section_deinit()

void critical_section_deinit ( critical_section_t crit_sec)

De-Initialise a critical_section created by the critical_section_init method.

This method is only used to free the associated spin lock allocated via the critical_section_init method (it should not be used to de-initialize a spin lock created via critical_section_init_with_lock_num). After this call, the critical section is invalid

Parameters
crit_secPointer to critical_section structure

◆ critical_section_enter_blocking()

static __force_inline void critical_section_enter_blocking ( critical_section_t crit_sec)
static

Enter a critical_section.

If the spin lock associated with this critical section is in use, then this method will block until it is released.

Parameters
crit_secPointer to critical_section structure

◆ critical_section_exit()

static __force_inline void critical_section_exit ( critical_section_t crit_sec)
static

Release a critical_section.

Parameters
crit_secPointer to critical_section structure

◆ critical_section_init()

void critical_section_init ( critical_section_t crit_sec)

Initialise a critical_section structure allowing the system to assign a spin lock number.

The critical section is initialized ready for use, and will use a (possibly shared) spin lock number assigned by the system. Note that in general it is unlikely that you would be nesting critical sections, however if you do so you must use critical_section_init_with_lock_num to ensure that the spin locks used are different.

Parameters
crit_secPointer to critical_section structure

◆ critical_section_init_with_lock_num()

void critical_section_init_with_lock_num ( critical_section_t crit_sec,
uint  lock_num 
)

Initialise a critical_section structure assigning a specific spin lock number.

Parameters
crit_secPointer to critical_section structure
lock_numthe specific spin lock number to use

◆ critical_section_is_initialized()

static bool critical_section_is_initialized ( critical_section_t crit_sec)
inlinestatic

Test whether a critical_section has been initialized.

Parameters
crit_secPointer to critical_section structure
Returns
true if the critical section is initialized, false otherwise