All Classes Namespaces Functions Variables Typedefs Enumerations Friends
worker_progress_thread.h
1 
5 #pragma once
6 
7 #include <functional>
8 #include <memory>
9 #include <mutex>
10 #include <thread>
11 
12 #include <ucxx/delayed_submission.h>
13 
14 namespace ucxx {
15 
21 typedef std::function<void(void)> SignalWorkerFunction;
22 
29 typedef std::function<void(void*)> ProgressThreadStartCallback;
30 
38 
49  private:
50  std::thread _thread{};
51  std::shared_ptr<bool> _stop{std::make_shared<bool>(false)};
52  bool _pollingMode{false};
53  SignalWorkerFunction _signalWorkerFunction{
54  nullptr};
56  ProgressThreadStartCallback _startCallback{
57  nullptr};
58  ProgressThreadStartCallbackArg _startCallbackArg{
59  nullptr};
60  std::shared_ptr<DelayedSubmissionCollection> _delayedSubmissionCollection{
61  nullptr};
62 
84  static void progressUntilSync(
85  std::function<bool(void)> progressFunction,
86  std::shared_ptr<bool> stop,
87  std::function<void(void)> setThreadId,
88  ProgressThreadStartCallback startCallback,
89  ProgressThreadStartCallbackArg startCallbackArg,
90  std::shared_ptr<DelayedSubmissionCollection> delayedSubmissionCollection);
91 
92  public:
93  WorkerProgressThread() = default;
95  WorkerProgressThread& operator=(WorkerProgressThread const&) = delete;
97  WorkerProgressThread& operator=(WorkerProgressThread&& o) = default;
98 
137  std::function<bool(void)> progressFunction,
138  std::function<void(void)> signalWorkerFunction,
139  std::function<void(void)> setThreadId,
140  ProgressThreadStartCallback startCallback,
141  ProgressThreadStartCallbackArg startCallbackArg,
142  std::shared_ptr<DelayedSubmissionCollection> delayedSubmissionCollection);
143 
150 
156  [[nodiscard]] bool pollingMode() const;
157 
163  [[nodiscard]] std::thread::id getId() const;
164 
170  [[nodiscard]] bool isRunning() const;
171 
172  void stop();
173 };
174 
175 } // namespace ucxx
A thread to progress a ucxx::Worker.
Definition: worker_progress_thread.h:48
WorkerProgressThread(const bool pollingMode, std::function< bool(void)> progressFunction, std::function< void(void)> signalWorkerFunction, std::function< void(void)> setThreadId, ProgressThreadStartCallback startCallback, ProgressThreadStartCallbackArg startCallbackArg, std::shared_ptr< DelayedSubmissionCollection > delayedSubmissionCollection)
Constructor of shared_ptr<ucxx::Worker>.
std::thread::id getId() const
Returns the ID of the progress thread.
~WorkerProgressThread()
ucxx::WorkerProgressThread destructor.
bool isRunning() const
Returns whether the thread is running.
bool pollingMode() const
Returns whether the thread was created for polling progress mode.
Definition: address.h:15
std::function< void(void *)> ProgressThreadStartCallback
A user-defined function to execute at the start of the progress thread.
Definition: worker_progress_thread.h:29
void * ProgressThreadStartCallbackArg
Data for the user-defined function provided to progress thread start callback.
Definition: worker_progress_thread.h:37
std::function< void(void)> SignalWorkerFunction
A user-defined function used to wake the worker.
Definition: worker_progress_thread.h:21