Documentation of UrbanFireXDT
Documentation of UrbanFireXDT
Loading...
Searching...
No Matches
worker_threads.hpp
Go to the documentation of this file.
1/*
2 * worker_threads.hpp
3 *
4 * It contains the definition of classes required for
5 * the worker threads.
6 *
7 */
8
9#ifndef WORKER_THREADS_HPP
10#define WORKER_THREADS_HPP
11
12#include <atomic>
13#include <condition_variable>
14#include <latch>
15#include <list>
16#include <mutex>
17#include <thread>
18#include <vector>
19
20// The following classes are defined in this header file:
23
24#include "global.h"
25#include "units.h"
26
34 private:
36
37 public:
44 CUControllerThreadGroupManager(const std::vector<ControlUnit*>* subsection = NULL);
45
47 //static void InitializeThreadGroupManager();
48
55
62
71 void executeOneStep(unsigned long ts/*, const std::vector<ControlUnit*>* subsection = NULL*/);
72
79
87
91 // static void Vacuum();
92
93 private:
94 //bool initialized; /* = false */ ///< True, if the manager is already initialized
95 std::vector<CUControllerWorkerThread*> worker_threads;
96 std::latch* all_workers_finished_latch;
97 // only required if work stealing is used
98 std::atomic<unsigned long> work_stealing_next_cuID;
99 std::mutex work_stealing_mtx;
100};
101
109 public:
118 CUControllerWorkerThread(const std::list<ControlUnit*>* connected_units_, CUControllerThreadGroupManager& caller);
126 void start();
127 void stop();
128
139 void executeOneStepForAllConnCUs(unsigned long ts/*, const std::vector<ControlUnit*>* subsection = NULL*/);
140
144 bool isIdling() const { return atomic_flag_idling; }
145
149 bool errorHappened() const { return error_happened; }
150
151 private:
152 CUControllerThreadGroupManager& thread_group_manager;
153 bool use_work_stealing;
154 std::vector<ControlUnit*> connected_units;
155 std::thread current_thread;
156 std::mutex mtx;
157 std::condition_variable cv;
158 std::atomic<bool> atomic_flag_stop;
159 std::atomic<bool> atomic_flag_exec;
160 std::atomic<bool> atomic_flag_running;
161 std::atomic<bool> atomic_flag_idling;
162 //
163 std::atomic<bool> error_happened;
164 //
165 std::atomic<unsigned long> atomic_param_ts;
166 //
167 void run();
168};
169
170#endif
171
Definition worker_threads.hpp:33
ControlUnit * getNextControlUnit()
Definition worker_threads.cpp:112
void executeOneStep(unsigned long ts)
Definition worker_threads.cpp:86
void stopAllWorkerThreads()
Definition worker_threads.cpp:80
bool waitForWorkersToFinish()
Definition worker_threads.cpp:99
void startAllWorkerThreads()
Definition worker_threads.cpp:74
~CUControllerThreadGroupManager()
Definition worker_threads.cpp:65
Definition worker_threads.hpp:108
void executeOneStepForAllConnCUs(unsigned long ts)
Definition worker_threads.cpp:217
bool isIdling() const
Definition worker_threads.hpp:144
void stop()
Stops this working thread.
Definition worker_threads.cpp:207
bool errorHappened() const
Definition worker_threads.hpp:149
void start()
Starts this thread. This method has to be called before the call of executeOneStepForAllConnCUs().
Definition worker_threads.cpp:191
~CUControllerWorkerThread()
Definition worker_threads.cpp:172
Definition units.h:162