Zephyr API Documentation  3.7.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mpsc_lockfree.h File Reference

A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list. More...

#include <stdint.h>
#include <stdbool.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/kernel.h>

Go to the source code of this file.

Data Structures

struct  mpsc_node
 Queue member. More...
 
struct  mpsc
 MPSC Queue. More...
 

Macros

#define mpsc_ptr_get(ptr)   atomic_ptr_get(&(ptr))
 
#define mpsc_ptr_set(ptr, val)   atomic_ptr_set(&(ptr), val)
 
#define mpsc_ptr_set_get(ptr, val)   atomic_ptr_set(&(ptr), val)
 
#define MPSC_INIT(symbol)
 Static initializer for a mpsc queue.
 

Typedefs

typedef atomic_ptr_t mpsc_ptr_t
 

Functions

static void mpsc_init (struct mpsc *q)
 Initialize queue.
 
static ALWAYS_INLINE void mpsc_push (struct mpsc *q, struct mpsc_node *n)
 Push a node.
 
static struct mpsc_nodempsc_pop (struct mpsc *q)
 Pop a node off of the list.
 

Detailed Description

A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list.

Ordering is First-In-First-Out.

Based on the well known and widely used wait-free MPSC queue described by Dmitry Vyukov with some slight changes to account for needs of an RTOS on a variety of archs. Both consumer and producer are wait free. No CAS loop or lock is needed.

An MPSC queue is safe to produce or consume in an ISR with O(1) push/pop.

Warning
MPSC is not safe to consume in multiple execution contexts.