Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
mpsc_queue_impl.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_impl.h
10 //! @brief Multi-producer single-consumer queue internal implementation.
11 
12 #ifndef ROC_CORE_MPSC_QUEUE_IMPL_H_
13 #define ROC_CORE_MPSC_QUEUE_IMPL_H_
14 
16 
17 namespace roc {
18 namespace core {
19 
20 //! Multi-producer single-consumer queue internal implementation class.
21 //!
22 //! Provides only push/pop functionality. Ownership is left up to the main MpscQueue
23 //! class.
25 public:
26  MpscQueueImpl();
27 
28  ~MpscQueueImpl();
29 
30  //! Add object to the end of the queue.
31  void push_back(MpscQueueData* node);
32 
33  //! Remove object from the beginning of the queue.
34  MpscQueueData* pop_front(bool can_spin);
35 
36 private:
37  void push_node_(MpscQueueData* node);
38  MpscQueueData* pop_node_(bool can_spin);
39 
40  MpscQueueData* wait_next_(MpscQueueData* node);
41  MpscQueueData* try_wait_next_(MpscQueueData* node);
42 
43  void change_owner_(MpscQueueData* node, void* from, void* to);
44 
45  MpscQueueData* tail_;
46  MpscQueueData* head_;
47 
48  MpscQueueData stub_;
49 };
50 
51 } // namespace core
52 } // namespace roc
53 
54 #endif // ROC_CORE_MPSC_QUEUE_IMPL_H_
Multi-producer single-consumer queue internal implementation class.
MpscQueueData * pop_front(bool can_spin)
Remove object from the beginning of the queue.
void push_back(MpscQueueData *node)
Add object to the end of the queue.
MpscQueue node.
Root namespace.
MpscQueue node internal data.