DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
pipeline.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3// Fork baseline commit: oks-08-03-04 (2022-04-14).
4// Renamed since fork: no.
5
7//
8// copy from IPC
9//
11
12#include "oks/pipeline.hpp"
13#include <boost/bind/bind.hpp>
14
15namespace dunedaq {
16namespace oks {
17
18bool
20{
21 boost::mutex::scoped_lock lock( m_mutex );
22 if ( !m_running && m_idle )
23 {
24 m_job = job;
25 m_idle = false;
26 m_condition.notify_one();
27 return true;
28 }
29 return false;
30}
31
32void
34{
35 {
36 boost::mutex::scoped_lock lock( m_mutex );
37 m_pipeline.m_barrier.wait();
38 }
39 while ( true )
40 {
41 {
42 boost::mutex::scoped_lock lock( m_mutex );
43 m_running = true;
44 }
45 while ( !m_idle ) {
46 m_job->run();
47 delete m_job;
48 m_idle = !m_pipeline.getJob( m_job );
49 }
50 {
51 boost::mutex::scoped_lock lock( m_mutex );
52 m_running = false;
53 if ( m_shutdown )
54 break;
55 if ( m_stop ) {
56 m_pipeline.m_barrier.wait();
57 m_stop = false;
58 }
59 if ( m_idle )
60 m_condition.wait( lock );
61 }
62 }
63}
64
65void
67{
68 boost::mutex::scoped_lock lock( m_mutex );
69 m_shutdown = true;
70 m_condition.notify_one( );
71}
72
73void
75{
76 boost::mutex::scoped_lock lock( m_mutex );
77 m_stop = true;
78 m_condition.notify_one( );
79}
80
82 : m_barrier( size + 1 )
83{
84 for ( size_t i = 0; i < size; ++i )
85 {
86 m_workers.push_back( WorkerPtr( new Worker( *this ) ) );
87 m_pool.create_thread( boost::bind( &Worker::run, m_workers.back().get() ) );
88 }
89 m_barrier.wait();
90}
91
93{
95 for ( size_t i = 0; i < m_workers.size(); ++i )
96 {
97 m_workers[i] -> shutdown();
98 }
99 m_pool.join_all();
100}
101
102void
104{
105 for ( size_t i = 0; i < m_workers.size(); ++i )
106 {
107 if ( m_workers[i] -> setJob( job ) )
108 {
109 return;
110 }
111 }
112 boost::mutex::scoped_lock lock( m_mutex );
113 m_jobs.push( job );
114}
115
116void
118{
119 {
120 boost::mutex::scoped_lock lock( m_mutex );
121 while ( !m_jobs.empty() )
122 {
123 m_condition.wait( lock );
124 }
125 }
126 for ( size_t i = 0; i < m_workers.size(); ++i )
127 {
128 m_workers[i] -> stop();
129 }
130 m_barrier.wait();
131}
132
133bool
135{
136 boost::mutex::scoped_lock lock( m_mutex );
137 if ( !m_jobs.empty() )
138 {
139 job = m_jobs.front();
140 m_jobs.pop();
141 m_condition.notify_one( );
142 return true;
143 }
144 return false;
145}
146
147} // namespace oks
148} // namespace dunedaq
boost::condition m_condition
Definition pipeline.hpp:84
std::queue< OksJob * > m_jobs
Definition pipeline.hpp:88
std::vector< WorkerPtr > m_workers
Definition pipeline.hpp:87
bool getJob(OksJob *&job)
Definition pipeline.cpp:134
std::shared_ptr< Worker > WorkerPtr
Definition pipeline.hpp:75
boost::thread_group m_pool
Definition pipeline.hpp:86
void addJob(OksJob *job)
Definition pipeline.cpp:103
boost::barrier m_barrier
Definition pipeline.hpp:85
Including Qt Headers.
Definition module.cpp:16
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size