11#include <condition_variable>
29# pragma clang diagnostic push
30# pragma clang diagnostic ignored "-Wweak-vtables"
37# pragma clang diagnostic pop
41 virtual void run() = 0;
44 template<
typename Function>
49 template<
typename FunctionFwd>
61 using TaskPackage = std::pair<std::unique_ptr<Task>, std::promise<void>>;
82 std::unique_lock<std::mutex> lock{
m_state->m_mutex};
90 if(std::this_thread::get_id() ==
m_thread.get_id())
104 template<
typename NullaryFunction>
105 auto submit(NullaryFunction&& nf) -> std::future<void>
107 using DecayedFunction = std::decay_t<NullaryFunction>;
109 std::is_void_v<std::invoke_result_t<DecayedFunction>>,
110 "Submitted function must not have any arguments and return void.");
116 std::promise<void>{});
117 auto f = tp.second.get_future();
119 std::unique_lock<std::mutex> lock{
m_state->m_mutex};
120 m_state->m_tasks.emplace(std::move(tp));
131 std::unique_lock<std::mutex> lock{
m_state->m_mutex};
132 return m_state->m_tasks.empty();
151 std::promise<void> taskPromise;
152 std::exception_ptr eptr;
155 std::unique_ptr<Task> task =
nullptr;
157 std::unique_lock<std::mutex> lock{state->m_mutex};
160 [&state, &st] {
return st.stop_requested() || !state->m_tasks.empty(); });
162 if(st.stop_requested() && state->m_tasks.empty())
165 task = std::move(state->m_tasks.front().first);
166 taskPromise = std::move(state->m_tasks.front().second);
175 eptr = std::current_exception();
178 std::unique_lock<std::mutex> lock{state->m_mutex};
181 state->m_tasks.pop();
188 taskPromise.set_exception(std::move(eptr));
190 taskPromise.set_value();
std::shared_ptr< State > m_state
Hold data shared between this call and the thread processing the tasts.
CallbackThread(uint32_t numaIdx)
std::pair< std::unique_ptr< Task >, std::promise< void > > TaskPackage
auto submit(NullaryFunction &&nf) -> std::future< void >
It is guaranteed that the task is fully destroyed before the future's result is set.
auto startWorkerThread() -> void
#define ALPAKA_COMP_CLANG
constexpr uint32_t allNumaDomains
Constant to select all NUMA domains.
void setThreadAffinity(uint32_t numaIdx)
Set the affinity of the current thread to all cores of the NUMA domain.
FunctionHolder(FunctionFwd &&func)
std::queue< TaskPackage > m_tasks
std::condition_variable m_cond