Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
mpsc_queue_node.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/mpsc_queue_node.h
10
//! @brief MpscQueue node.
11
12
#ifndef ROC_CORE_MPSC_QUEUE_NODE_H_
13
#define ROC_CORE_MPSC_QUEUE_NODE_H_
14
15
#include "
roc_core/atomic.h
"
16
#include "
roc_core/macro_helpers.h
"
17
#include "
roc_core/noncopyable.h
"
18
#include "
roc_core/panic.h
"
19
20
namespace
roc
{
21
namespace
core
{
22
23
//! MpscQueue node internal data.
24
struct
MpscQueueData {
25
//! Next list element.
26
MpscQueueData*
next
;
27
28
//! Pointer to the containing queue.
29
void
*
queue
;
30
31
MpscQueueData()
32
:
next
(NULL)
33
,
queue
(NULL) {
34
}
35
};
36
37
//! Base class for MpscQueue element.
38
//! @remarks
39
//! Object should inherit this class to be able to be a member of MpscQueue.
40
//! Tag allows to inherit multiple copies of ListNode and include same
41
//! object into multiple lists.
42
template
<
class
Tag =
void
>
43
class
MpscQueueNode
:
public
NonCopyable<MpscQueueNode<Tag> > {
44
public
:
45
~MpscQueueNode
() {
46
if
(mpsc_queue_data_.queue) {
47
roc_panic
(
"mpsc node: attempt to destroy node while it's still in queue"
);
48
}
49
}
50
51
//! Get pointer to parent node from pointer to internal data.
52
static
MpscQueueNode
*
mpsc_queue_node
(
MpscQueueData
* data) {
53
return
ROC_CONTAINER_OF
(data,
MpscQueueNode
, mpsc_queue_data_);
54
}
55
56
//! Get pointer to internal data.
57
MpscQueueData
*
mpsc_queue_data
()
const
{
58
return
&mpsc_queue_data_;
59
}
60
61
private
:
62
mutable
MpscQueueData
mpsc_queue_data_;
63
};
64
65
}
// namespace core
66
}
// namespace roc
67
68
#endif
// ROC_CORE_MPSC_QUEUE_NODE_H_
atomic.h
Atomic.
roc::core::MpscQueueNode
Base class for MpscQueue element.
Definition
mpsc_queue_node.h:43
roc::core::MpscQueueNode::mpsc_queue_data
MpscQueueData * mpsc_queue_data() const
Get pointer to internal data.
Definition
mpsc_queue_node.h:57
roc::core::MpscQueueNode::mpsc_queue_node
static MpscQueueNode * mpsc_queue_node(MpscQueueData *data)
Get pointer to parent node from pointer to internal data.
Definition
mpsc_queue_node.h:52
macro_helpers.h
Helper macros.
ROC_CONTAINER_OF
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition
macro_helpers.h:37
roc::core
General-purpose building blocks and platform abstraction layer.
roc
Root namespace.
noncopyable.h
Non-copyable object.
panic.h
Panic.
roc_panic
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition
panic.h:50
roc::core::MpscQueueData
MpscQueue node internal data.
Definition
mpsc_queue_node.h:24
roc::core::MpscQueueData::queue
void * queue
Pointer to the containing queue.
Definition
mpsc_queue_node.h:29
roc::core::MpscQueueData::next
MpscQueueData * next
Next list element.
Definition
mpsc_queue_node.h:26
roc_core
mpsc_queue_node.h
Generated by
1.17.0