Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
"
17
#include "
roc_core/noncopyable.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
24
namespace
roc
{
25
namespace
packet
{
26
27
//! Concurrent blocking packet queue.
28
class
ConcurrentQueue
:
public
IReader
,
public
IWriter
,
public
core::NonCopyable
<> {
29
public
:
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.
44
virtual
ROC_ATTR_NODISCARD
status::StatusCode
read
(
PacketPtr
&);
45
46
//! Add packet to the queue.
47
//! Wait-free operation.
48
virtual
ROC_ATTR_NODISCARD
status::StatusCode
write
(
const
PacketPtr
&
packet
);
49
50
private
:
51
core::Optional<core::Semaphore>
write_sem_;
52
core::Mutex
read_mutex_;
53
core::MpscQueue<Packet>
queue_;
54
};
55
56
}
// namespace packet
57
}
// namespace roc
58
59
#endif
// ROC_PACKET_CONCURRENT_QUEUE_H_
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::MpscQueue
Thread-safe lock-free node-based intrusive multi-producer single-consumer queue.
Definition
mpsc_queue.h:45
roc::core::Mutex
Mutex.
Definition
mutex.h:31
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::core::Optional
Optionally constructed object.
Definition
optional.h:25
roc::packet::ConcurrentQueue::write
virtual ROC_ATTR_NODISCARD status::StatusCode write(const PacketPtr &packet)
Add packet to the queue. Wait-free operation.
roc::packet::ConcurrentQueue::ConcurrentQueue
ConcurrentQueue(Mode mode)
Initialize. mode defines whether reads will be blocking.
roc::packet::ConcurrentQueue::read
virtual ROC_ATTR_NODISCARD status::StatusCode read(PacketPtr &)
Read next packet. If reads are not concurrent, and queue is non-blocking, then reads are wait-free....
roc::packet::ConcurrentQueue::Mode
Mode
Queue mode.
Definition
concurrent_queue.h:31
roc::packet::ConcurrentQueue::NonBlocking
@ NonBlocking
Read operation returns null if queue is empty.
Definition
concurrent_queue.h:33
roc::packet::ConcurrentQueue::Blocking
@ Blocking
Read operation blocks until queue is non-empty.
Definition
concurrent_queue.h:32
roc::packet::IReader
Packet reader interface.
Definition
ireader.h:23
roc::packet::IWriter
Packet writer interface.
Definition
iwriter.h:23
ireader.h
Packet reader interface.
iwriter.h
Packet writer interface.
mpsc_queue.h
Multi-producer single-consumer queue.
mutex.h
Mutex.
roc::packet
Network packets and packet processing.
roc::packet::PacketPtr
core::SharedPtr< Packet > PacketPtr
Packet smart pointer.
Definition
packet.h:34
roc
Root namespace.
noncopyable.h
Non-copyable object.
optional.h
Optionally constructed object.
packet.h
Packet.
roc::status::StatusCode
StatusCode
Status code.
Definition
status_code.h:19
roc_packet
concurrent_queue.h
Generated by
1.17.0