Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
concurrent_queue.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc 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_packet/concurrent_queue.h
10 //! @brief Concurrent blocking packet queue.
11 
12 #ifndef ROC_PACKET_CONCURRENT_QUEUE_H_
13 #define ROC_PACKET_CONCURRENT_QUEUE_H_
14 
15 #include "roc_core/cond.h"
16 #include "roc_core/list.h"
17 #include "roc_core/mutex.h"
18 #include "roc_core/noncopyable.h"
19 #include "roc_packet/ireader.h"
20 #include "roc_packet/iwriter.h"
21 #include "roc_packet/packet.h"
22 
23 namespace roc {
24 namespace packet {
25 
26 //! Concurrent blocking packet queue.
27 class ConcurrentQueue : public IReader, public IWriter, public core::NonCopyable<> {
28 public:
30 
31  //! Read next packet.
32  //! @remarks
33  //! Blocks until the queue becomes non-empty and returns the first
34  //! packet from the queue.
35  virtual PacketPtr read();
36 
37  //! Add packet to the queue.
38  //! @remarks
39  //! Adds packet to the end of the queue.
40  virtual void write(const PacketPtr& packet);
41 
42 private:
43  core::Mutex mutex_;
44  core::Cond cond_;
45  core::List<Packet> list_;
46 };
47 
48 } // namespace packet
49 } // namespace roc
50 
51 #endif // ROC_PACKET_CONCURRENT_QUEUE_H_
virtual PacketPtr read()
Read next packet.
Packet reader interface.
Packet reader interface.
Definition: ireader.h:21
Condition variable.
Definition: cond.h:25
Root namespace.
Intrusive doubly-linked list.
Definition: list.h:31
Mutex.
Definition: mutex.h:27
Packet writer interface.
Packet writer interface.
Definition: iwriter.h:21
Intrusive doubly-linked list.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Mutex.
virtual void write(const PacketPtr &packet)
Add packet to the queue.
Concurrent blocking packet queue.
Packet.
Condition variable.
Non-copyable object.