Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
concurrent_queue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 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_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/mpsc_queue.h"
16#include "roc_core/mutex.h"
18#include "roc_core/optional.h"
19#include "roc_core/semaphore.h"
20#include "roc_packet/ireader.h"
21#include "roc_packet/iwriter.h"
22#include "roc_packet/packet.h"
23
24namespace roc {
25namespace packet {
26
27//! Concurrent blocking packet queue.
28class ConcurrentQueue : public IReader, public IWriter, public core::NonCopyable<> {
29public:
30 //! Queue mode.
31 enum Mode {
32 Blocking, //!< Read operation blocks until queue is non-empty.
33 NonBlocking //!< Read operation returns null if queue is empty.
34 };
35
36 //! Initialize.
37 //! @p mode defines whether reads will be blocking.
38 explicit ConcurrentQueue(Mode mode);
39
40 //! Read next packet.
41 //! If reads are not concurrent, and queue is non-blocking, then
42 //! reads are wait-free. Otherwise they may block.
43 //! @see Mode.
45
46 //! Add packet to the queue.
47 //! Wait-free operation.
49
50private:
52 core::Mutex read_mutex_;
54};
55
56} // namespace packet
57} // namespace roc
58
59#endif // ROC_PACKET_CONCURRENT_QUEUE_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Base class for non-copyable objects.
Definition noncopyable.h:23
Concurrent blocking packet queue.
virtual status::StatusCode read(PacketPtr &)
Read next packet. If reads are not concurrent, and queue is non-blocking, then reads are wait-free....
ConcurrentQueue(Mode mode)
Initialize. mode defines whether reads will be blocking.
@ NonBlocking
Read operation returns null if queue is empty.
@ Blocking
Read operation blocks until queue is non-empty.
virtual status::StatusCode write(const PacketPtr &packet)
Add packet to the queue. Wait-free operation.
Packet reader interface.
Definition ireader.h:23
Packet writer interface.
Definition iwriter.h:23
Packet reader interface.
Packet writer interface.
Multi-producer single-consumer queue.
Mutex.
StatusCode
Status code.
Definition status_code.h:19
Root namespace.
Non-copyable object.
Optionally constructed object.
Packet.