libe3 0.2.5
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
mpmc_queue.hpp File Reference

Lock-free bounded Multi-Producer Multi-Consumer (MPMC) ring buffer. More...

#include <atomic>
#include <cstddef>
#include <new>

Go to the source code of this file.

Classes

class  libe3::MpmcQueue< T >
 Lock-free bounded MPMC ring buffer. More...

Namespaces

namespace  libe3

Functions

void libe3::cpu_relax () noexcept
 Emit a CPU-level pause/yield hint inside spin-wait loops.

Variables

static constexpr size_t libe3::CACHE_LINE_SIZE = 64
 Assumed cache-line size (bytes) used for alignment padding.

Detailed Description

Lock-free bounded Multi-Producer Multi-Consumer (MPMC) ring buffer.

Implements Dmitry Vyukov's MPMC bounded queue algorithm. Each slot carries an atomic sequence counter that acts as a generation tag, eliminating the need for CAS on the data itself and making the queue safe for any number of concurrent producers and consumers with very low overhead.

Design highlights:

  • Zero locks / zero condition variables in the fast path
  • head_ and tail_ are on separate cache lines to eliminate false sharing
  • Capacity is rounded up to the nearest power of two for cheap masking
  • Provides try_push / try_pop (non-blocking) used by LockFreeQueue

SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University SPDX-License-Identifier: Apache-2.0

Definition in file mpmc_queue.hpp.