Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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.
27 
28  //! Pointer to the containing queue.
29  void* queue;
30 
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.
53  return ROC_CONTAINER_OF(data, MpscQueueNode, mpsc_queue_data_);
54  }
55 
56  //! Get pointer to internal data.
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.
Base class for MpscQueue element.
static MpscQueueNode * mpsc_queue_node(MpscQueueData *data)
Get pointer to parent node from pointer to internal data.
MpscQueueData * mpsc_queue_data() const
Get pointer to internal data.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: macro_helpers.h:37
Root namespace.
Non-copyable object.
Panic.
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition: panic.h:50
MpscQueue node internal data.
void * queue
Pointer to the containing queue.
MpscQueueData * next
Next list element.