v2.0.0
Functions
critical_section
High Level APIs » pico_sync

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

## Functions
void | critical_section_init (critical_section_t *crit_sec)
| Initialise a critical_section structure allowing the system to assign a spin lock number. More...
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. More...
static void | critical_section_enter_blocking (critical_section_t *crit_sec)
| Enter a critical_section. More...
static void | critical_section_exit (critical_section_t *crit_sec)
| Release a critical_section. More...
void | critical_section_deinit (critical_section_t *crit_sec)
| De-Initialise a critical_section created by the critical_section_init method. More...

## 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.

## 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_sec | Pointer to critical_section structure

## ◆ critical_section_enter_blocking()

static void critical_section_enter_blocking | ( | critical_section_t * | crit_sec | ) |
| inlinestatic

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_sec | Pointer to critical_section structure

## ◆ critical_section_exit()

static void critical_section_exit | ( | critical_section_t * | crit_sec | ) |
| inlinestatic

Release a critical_section.

Parameters

  crit_sec | Pointer 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_sec | Pointer 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_sec | Pointer to critical_section structure
  lock_num | the specific spin lock number to use