Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
mpmc_queue.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: © 2019, 2023 Alexandros Theodotou <alex@zrythm.org>
2
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
/*
4
* This file incorporates work covered by the following copyright and
5
* permission notice:
6
*
7
* ---
8
*
9
* Copyright (C) 2010-2011 Dmitry Vyukov
10
* Copyright (C) 2017, 2019 Robin Gareus <robin@gareus.org>
11
*
12
* This program is free software: you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation, either version 2 of the License, or
15
* (at your option) any later version.
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program. If not, see <https://www.gnu.org/licenses/>.
24
*
25
* ---
26
*/
27
35
#ifndef __UTILS_MPMC_QUEUE_H__
36
#define __UTILS_MPMC_QUEUE_H__
37
38
#include <cstddef>
39
40
#define MPMC_USE_STD_ATOMIC 1
41
42
#if MPMC_USE_STD_ATOMIC
43
# include <atomic>
44
# define MPMC_QUEUE_TYPE std::atomic<size_t>
45
#else
46
# include <glib.h>
47
# define MPMC_QUEUE_TYPE guint
48
#endif
49
56
typedef
struct
cell_t
57
{
58
MPMC_QUEUE_TYPE sequence;
59
void
* data;
60
}
cell_t
;
61
68
typedef
struct
MPMCQueue
69
{
70
char
pad0[64];
71
cell_t
* buffer;
72
size_t
buffer_mask;
73
char
pad1[64 -
sizeof
(
cell_t
*) -
sizeof
(
size_t
)];
74
MPMC_QUEUE_TYPE enqueue_pos;
75
char
pad2[64 -
sizeof
(size_t)];
76
MPMC_QUEUE_TYPE dequeue_pos;
77
char
pad3[64 -
sizeof
(size_t)];
78
79
}
MPMCQueue
;
80
81
MPMCQueue
*
82
mpmc_queue_new (
void
);
83
84
NONNULL
void
85
mpmc_queue_reserve (
MPMCQueue
* self,
size_t
buffer_size);
86
87
NONNULL
void
88
mpmc_queue_free (
MPMCQueue
* self);
89
90
NONNULL
void
91
mpmc_queue_clear (
MPMCQueue
* self);
92
93
HOT NONNULL
int
94
mpmc_queue_push_back (
MPMCQueue
* self,
void
*
const
data);
95
96
HOT NONNULL
int
97
mpmc_queue_dequeue (
MPMCQueue
* self,
void
** data);
98
103
#endif
MPMCQueue
Multiple Producer Multiple Consumer lock-free queue.
Definition
mpmc_queue.h:69
cell_t
Definition
mpmc_queue.h:57
utils
mpmc_queue.h
Generated by
1.11.0