ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
spsc.h File Reference

Lock-free single-producer single-consumer queue of fixed-size items. More...

#include <stdint.h>
#include <string.h>
Include dependency graph for spsc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  spsc_t
 

Macros

#define SPSC_BARRIER()   __sync_synchronize()
 
#define SPSC_DEFINE(name, type, n)
 

Functions

static void spsc_reset (spsc_t *q)
 
static int spsc_push (spsc_t *q, const void *it)
 
static int spsc_pop (spsc_t *q, void *it)
 
static uint32_t spsc_count (const spsc_t *q)
 

Detailed Description

Lock-free single-producer single-consumer queue of fixed-size items.

One thread pushes, one thread pops; no mutex, no blocking, safe on Cortex-M (32-bit aligned index stores are atomic, barriers order data and index). Capacity N must be a power of 2.

Definition in file spsc.h.

Macro Definition Documentation

◆ SPSC_BARRIER

#define SPSC_BARRIER ( )    __sync_synchronize()

Definition at line 18 of file spsc.h.

◆ SPSC_DEFINE

#define SPSC_DEFINE (   name,
  type,
  n 
)
Value:
static uint8_t name##_buf[(n) * sizeof(type)]; \
static spsc_t name = { 0u, 0u, (n) - 1u, sizeof(type), name##_buf }
uint32_t n
Definition calib_mgr.c:35
Definition spsc.h:21

Definition at line 29 of file spsc.h.

Function Documentation

◆ spsc_reset()

static void spsc_reset ( spsc_t *  q)
inlinestatic

Definition at line 33 of file spsc.h.

References spsc_t::head, and spsc_t::tail.

Referenced by batt_task_init(), ext_init(), fc_init(), fsh_reset(), and log_task_init().

Here is the caller graph for this function:

◆ spsc_push()

static int spsc_push ( spsc_t *  q,
const void *  it 
)
inlinestatic

< full

Definition at line 35 of file spsc.h.

References spsc_t::buf, spsc_t::head, spsc_t::item, spsc_t::mask, SPSC_BARRIER, and spsc_t::tail.

Referenced by batt_task_post_scales(), event(), ext_step(), fc_batt_signal(), fc_post(), fsh_apply_post(), fsh_cal_push(), log_task_ble_cmd(), port_send(), result(), and to_app().

Here is the caller graph for this function:

◆ spsc_pop()

static int spsc_pop ( spsc_t *  q,
void *  it 
)
inlinestatic

< empty

Definition at line 45 of file spsc.h.

References spsc_t::buf, spsc_t::head, spsc_t::item, spsc_t::mask, SPSC_BARRIER, and spsc_t::tail.

Referenced by batt_task_step(), battery(), ext_take(), fc_service(), fc_take_event(), fc_take_result(), fsh_apply_take(), fsh_cal_pop(), log_task_ble_take(), log_task_step(), and log_task_usb_app_take().

Here is the caller graph for this function:

◆ spsc_count()

static uint32_t spsc_count ( const spsc_t *  q)
inlinestatic

Definition at line 56 of file spsc.h.

References spsc_t::head, and spsc_t::tail.

Referenced by port_room(), and port_room_ack().

Here is the caller graph for this function: