Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
BoundedSpscQueue.h
Go to the documentation of this file.
1
#pragma once
2
#include <array>
3
#include <atomic>
4
#include <cstddef>
5
6
namespace
Rendering
7
{
8
// One producer and one consumer. Full queues reject new work immediately;
9
// the consumer retains its slot until Release, even while its sink blocks.
10
template
<
class
T,std::
size_t
Capacity>
class
BoundedSpscQueue
11
{
12
static_assert
(Capacity>0,
"queue must have storage"
);
13
std::array<T,Capacity+1>
slots
{};
14
std::atomic<std::size_t>
write
{0};
15
std::atomic<std::size_t>
read
{0};
16
public
:
17
T*
Reserve
()
18
{
19
const
auto
at=
write
.load(std::memory_order_relaxed);
20
return
(at+1)%
slots
.size()==
read
.load(std::memory_order_acquire) ? nullptr : &
slots
[at];
21
}
22
void
Publish
() {
write
.store((
write
.load(std::memory_order_relaxed)+1)%
slots
.size(),std::memory_order_release);}
23
const
T*
Front
()
const
24
{
25
const
auto
at=
read
.load(std::memory_order_relaxed);
26
return
at==
write
.load(std::memory_order_acquire) ? nullptr : &
slots
[at];
27
}
28
void
Release
() {
read
.store((
read
.load(std::memory_order_relaxed)+1)%
slots
.size(),std::memory_order_release);}
29
};
30
}
Rendering::BoundedSpscQueue
Definition
BoundedSpscQueue.h:11
Rendering::BoundedSpscQueue::Release
void Release()
Definition
BoundedSpscQueue.h:28
Rendering::BoundedSpscQueue< OutputFrame, WriterQueueSize >::read
std::atomic< std::size_t > read
Definition
BoundedSpscQueue.h:15
Rendering::BoundedSpscQueue< OutputFrame, WriterQueueSize >::write
std::atomic< std::size_t > write
Definition
BoundedSpscQueue.h:14
Rendering::BoundedSpscQueue< OutputFrame, WriterQueueSize >::slots
std::array< OutputFrame, Capacity+1 > slots
Definition
BoundedSpscQueue.h:13
Rendering::BoundedSpscQueue::Front
const T * Front() const
Definition
BoundedSpscQueue.h:23
Rendering::BoundedSpscQueue::Publish
void Publish()
Definition
BoundedSpscQueue.h:22
Rendering::BoundedSpscQueue::Reserve
T * Reserve()
Definition
BoundedSpscQueue.h:17
Rendering
Definition
AdDiagnostics11.cpp:16
Rendering
BoundedSpscQueue.h
Generated on
for Rise by
1.18.0