in include/unifex/win32/windows_thread_pool.hpp [472:499]
explicit type(windows_thread_pool& pool, bool isStopPossible) {
::InitializeThreadpoolEnvironment(&environ_);
::SetThreadpoolCallbackPool(&environ_, pool.threadPool_);
// Give the optimiser a hand for cases where the parameter
// can never be true.
if constexpr (is_stop_never_possible_v<StopToken>) {
isStopPossible = false;
}
timer_ = ::CreateThreadpoolTimer(
isStopPossible ? &stoppable_timer_callback : &timer_callback, static_cast<void*>(this), &environ_);
if (timer_ == nullptr) {
DWORD errorCode = ::GetLastError();
::DestroyThreadpoolEnvironment(&environ_);
throw_(
std::system_error{static_cast<int>(errorCode), std::system_category(), "CreateThreadpoolTimer()"});
}
if (isStopPossible) {
state_ = new (std::nothrow) std::atomic<std::uint32_t>{not_started};
if (state_ == nullptr) {
::CloseThreadpoolTimer(timer_);
::DestroyThreadpoolEnvironment(&environ_);
throw_(std::bad_alloc{});
}
}
}