1#ifndef AMREX_BACKGROUND_THREAD_H_
2#define AMREX_BACKGROUND_THREAD_H_
3#include <AMReX_Config.H>
6#include <condition_variable>
45 void Submit (std::function<
void()>&& a_f);
49 void Submit (std::function<
void()>
const& a_f);
59 std::unique_ptr<std::thread> m_thread;
61 std::condition_variable m_job_cond;
62 std::condition_variable m_done_cond;
63 std::queue<std::function<void()> > m_func;
64 bool m_clearing =
false;
65 bool m_finalizing =
false;
Utility class running deferred work on a single background thread.
Definition AMReX_BackgroundThread.H:26
void Finish()
Block the caller until all queued jobs have completed.
Definition AMReX_BackgroundThread.cpp:52
BackgroundThread()
Launch the worker thread and initialize synchronization primitives.
Definition AMReX_BackgroundThread.cpp:5
void Submit(std::function< void()> &&a_f)
Enqueue a job that will run asynchronously on the worker thread.
Definition AMReX_BackgroundThread.cpp:38
~BackgroundThread()
Stop the worker thread and drain any queued work.
Definition AMReX_BackgroundThread.cpp:10
BackgroundThread & operator=(BackgroundThread const &)=delete
BackgroundThread(BackgroundThread const &)=delete
BackgroundThread(BackgroundThread &&)=delete
Definition AMReX_Amr.cpp:50