DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
iomanager
include
iomanager
queue
StdDeQueue.hpp
Go to the documentation of this file.
1
#ifndef IOMANAGER_INCLUDE_IOMANAGER_QUEUE_STDDEQUEUE_HPP_
2
#define IOMANAGER_INCLUDE_IOMANAGER_QUEUE_STDDEQUEUE_HPP_
3
14
15
#include "
iomanager/queue/Queue.hpp
"
16
17
#include <atomic>
18
#include <cassert>
19
#include <chrono>
20
#include <condition_variable>
21
#include <deque>
22
#include <functional>
23
#include <iostream>
24
#include <mutex>
25
#include <sstream>
26
#include <string>
27
#include <thread>
28
#include <type_traits>
29
#include <utility>
30
31
namespace
dunedaq::iomanager
{
36
template
<
class
T>
37
class
StdDeQueue
:
public
Queue
<T>
38
{
39
public
:
40
using
value_t
= T;
41
using
duration_t
=
typename
Queue<T>::duration_t
;
42
47
explicit
StdDeQueue
(
const
std::string& name,
size_t
capacity);
48
49
bool
can_pop
() const noexcept
override
{
return
this->
get_num_elements
() > 0; }
50
void
pop
(
value_t
& val,
const
duration_t
&)
override
;
// Throws QueueTimeoutExpired if a timeout occurs
51
bool
try_pop
(
value_t
& val,
const
duration_t
&)
override
;
52
53
bool
can_push
() const noexcept
override
{
return
this->
get_num_elements
() < this->
get_capacity
(); }
54
void
push
(
value_t
&&,
const
duration_t
&)
override
;
// Throws QueueTimeoutExpired if a timeout occurs
55
bool
try_push
(
value_t
&&,
const
duration_t
&)
override
;
56
57
size_t
get_capacity
()
const override
{
return
m_capacity
; }
58
59
size_t
get_num_elements
()
const override
{
return
m_size
.load(std::memory_order_acquire); }
60
61
// Delete the copy and move operations since various member data instances
62
// (e.g., of std::mutex or of std::atomic) aren't copyable or movable
63
64
StdDeQueue
(
const
StdDeQueue
&) =
delete
;
65
StdDeQueue
&
operator=
(
const
StdDeQueue
&) =
delete
;
66
StdDeQueue
(
StdDeQueue
&&) =
delete
;
67
StdDeQueue
&
operator=
(
StdDeQueue
&&) =
delete
;
68
69
private
:
70
void
try_lock_for
(std::unique_lock<std::mutex>&,
const
duration_t
&);
71
72
std::deque<value_t>
m_deque
;
73
size_t
m_capacity
;
74
std::atomic<size_t>
m_size
= 0;
75
76
std::mutex
m_mutex
;
77
std::condition_variable
m_no_longer_full
;
78
std::condition_variable
m_no_longer_empty
;
79
};
80
81
}
// namespace dunedaq::iomanager
82
83
#include "
detail/StdDeQueue.hxx
"
84
85
#endif
// IOMANAGER_INCLUDE_IOMANAGER_QUEUE_STDDEQUEUE_HPP_
StdDeQueue.hxx
dunedaq::iomanager::Queue::duration_t
std::chrono::milliseconds duration_t
Base duration type for timeouts.
Definition
Queue.hpp:40
dunedaq::iomanager::Queue::Queue
Queue(const std::string &name)
Queue Constructor.
Definition
Queue.hpp:46
dunedaq::iomanager::StdDeQueue::pop
void pop(value_t &val, const duration_t &) override
Pop the first value off of the queue.
Definition
StdDeQueue.hxx:44
dunedaq::iomanager::StdDeQueue::operator=
StdDeQueue & operator=(const StdDeQueue &)=delete
StdDeQueue is not copy-assignable.
dunedaq::iomanager::StdDeQueue::m_mutex
std::mutex m_mutex
Definition
StdDeQueue.hpp:76
dunedaq::iomanager::StdDeQueue::m_deque
std::deque< value_t > m_deque
Definition
StdDeQueue.hpp:72
dunedaq::iomanager::StdDeQueue::push
void push(value_t &&, const duration_t &) override
Push a value onto the Queue.
Definition
StdDeQueue.hxx:18
dunedaq::iomanager::StdDeQueue::try_lock_for
void try_lock_for(std::unique_lock< std::mutex > &, const duration_t &)
Definition
StdDeQueue.hxx:133
dunedaq::iomanager::StdDeQueue::m_size
std::atomic< size_t > m_size
Definition
StdDeQueue.hpp:74
dunedaq::iomanager::StdDeQueue::can_pop
bool can_pop() const noexcept override
Determine whether the Queue may be popped from.
Definition
StdDeQueue.hpp:49
dunedaq::iomanager::StdDeQueue::StdDeQueue
StdDeQueue(const std::string &name, size_t capacity)
StdDeQueue Constructor.
Definition
StdDeQueue.hxx:7
dunedaq::iomanager::StdDeQueue::can_push
bool can_push() const noexcept override
Determine whether the Queue may be pushed onto.
Definition
StdDeQueue.hpp:53
dunedaq::iomanager::StdDeQueue::try_pop
bool try_pop(value_t &val, const duration_t &) override
Definition
StdDeQueue.hxx:99
dunedaq::iomanager::StdDeQueue::duration_t
typename Queue< T >::duration_t duration_t
Type used for expressing timeouts.
Definition
StdDeQueue.hpp:41
dunedaq::iomanager::StdDeQueue::m_no_longer_full
std::condition_variable m_no_longer_full
Definition
StdDeQueue.hpp:77
dunedaq::iomanager::StdDeQueue::try_push
bool try_push(value_t &&, const duration_t &) override
Definition
StdDeQueue.hxx:71
dunedaq::iomanager::StdDeQueue::StdDeQueue
StdDeQueue(StdDeQueue &&)=delete
StdDeQueue is not move-constructible.
dunedaq::iomanager::StdDeQueue::m_no_longer_empty
std::condition_variable m_no_longer_empty
Definition
StdDeQueue.hpp:78
dunedaq::iomanager::StdDeQueue::StdDeQueue
StdDeQueue(const StdDeQueue &)=delete
StdDeQueue is not copy-constructible.
dunedaq::iomanager::StdDeQueue::value_t
T value_t
Type of data stored in the StdDeQueue.
Definition
StdDeQueue.hpp:40
dunedaq::iomanager::StdDeQueue::get_num_elements
size_t get_num_elements() const override
Definition
StdDeQueue.hpp:59
dunedaq::iomanager::StdDeQueue::operator=
StdDeQueue & operator=(StdDeQueue &&)=delete
StdDeQueue is not move-assignable.
dunedaq::iomanager::StdDeQueue::get_capacity
size_t get_capacity() const override
Get the capacity (max size) of the queue.
Definition
StdDeQueue.hpp:57
dunedaq::iomanager::StdDeQueue::m_capacity
size_t m_capacity
Definition
StdDeQueue.hpp:73
dunedaq::iomanager
Definition
IOManager.hxx:19
Queue.hpp
Generated on
for DUNE-DAQ by
1.17.0