27 thread = std::thread([
this]
29 std::unique_lock<std::mutex> lock(
runLock);
57 std::unique_lock<std::mutex> lock(
runLock);
74 std::unique_lock<std::mutex> lock(d->runLock);
75 d->pendingFunction = functionToRun;
76 d->isFunctionAboutToQuit =
true;
77 d->acquire.notify_one();
80 if (std::this_thread::get_id() != d->thread.get_id())
81 d->relased.wait(lock, [&d] {
return d->pendingFunction ==
nullptr; });
87 std::unique_lock<std::mutex> lock(d->runLock);
88 if (d->runningFunction !=
nullptr)
91 d->isFunctionAboutToQuit =
true;
92 d->pendingFunction = functionToRun;
93 d->acquire.notify_one();
96 if (std::this_thread::get_id() != d->thread.get_id())
97 d->relased.wait(lock, [&d] {
return d->pendingFunction ==
nullptr; });
std::function< void(const std::atomic_bool &isAboutToClose)> pendingFunction
std::condition_variable_any relased
std::function< void(const std::atomic_bool &isAboutToClose)> runningFunction
virtual ~SingleThreadPoolPrivate()
std::condition_variable_any acquire
std::atomic_bool isFunctionAboutToQuit
std::atomic_bool isThreadAboutToQuit
SingleThreadPoolPrivate()
void quit()
Sets the 'isAboutToClose' flag to 'true' and waits for the end of running function.
bool tryStart(const std::function< void(const std::atomic_bool &isAboutToClose)> &functionToRun)
If thread isn't available at the time of calling, then this function does nothing and returns false....
void start(const std::function< void(const std::atomic_bool &isAboutToClose)> &functionToRun)
Reserves a thread and uses it to run functionToRun. A running function can check the 'isAboutToClose'...
Namespace to encapsulate INDI client, drivers, and mediator classes.
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects