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;
96 
106 
117 
156  std::function<bool(void)> progressFunction,
157  std::function<void(void)> signalWorkerFunction,
158  std::function<void(void)> setThreadId,
159  ProgressThreadStartCallback startCallback,
160  ProgressThreadStartCallbackArg startCallbackArg,
161  std::shared_ptr<DelayedSubmissionCollection> delayedSubmissionCollection);
162 
169 
175  [[nodiscard]] bool pollingMode() const;
176 
182  [[nodiscard]] std::thread::id getId() const;
183 
189  [[nodiscard]] bool isRunning() const;
190 
196  void stop();
197 };
198 
199 } // namespace ucxx
A thread to progress a ucxx::Worker.
Definition: worker_progress_thread.h:48
void stop()
Stop the progress thread.
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 WorkerProgressThread.
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.
WorkerProgressThread(WorkerProgressThread &&o)=default
Move constructor of WorkerProgressThread.
WorkerProgressThread & operator=(WorkerProgressThread &&o)=default
Move assignment operator of WorkerProgressThread.
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