Block-Structured AMR Software Framework
AMReX_BackgroundThread.H
Go to the documentation of this file.
1 #ifndef AMREX_BACKGROUND_THREAD_H_
2 #define AMREX_BACKGROUND_THREAD_H_
3 #include <AMReX_Config.H>
4 
5 #include <algorithm>
6 #include <condition_variable>
7 #include <functional>
8 #include <memory>
9 #include <mutex>
10 #include <queue>
11 #include <thread>
12 
13 namespace amrex {
14 
16 {
17 public:
24 
25  void Submit (std::function<void()>&& a_f);
26  void Submit (std::function<void()> const& a_f);
27 
28  void Finish (); // Not required. Call this if you want all jobs to finish.
29 
30 private:
31  void do_job ();
32 
33  std::unique_ptr<std::thread> m_thread;
34  std::mutex m_mutx;
35  std::condition_variable m_job_cond;
36  std::condition_variable m_done_cond;
37  std::queue<std::function<void()> > m_func;
38  bool m_clearing = false;
39  bool m_finalizing = false;
40 };
41 
42 }
43 
44 #endif
Definition: AMReX_BackgroundThread.H:16
void Finish()
Definition: AMReX_BackgroundThread.cpp:52
BackgroundThread()
Definition: AMReX_BackgroundThread.cpp:5
bool m_finalizing
Definition: AMReX_BackgroundThread.H:39
std::unique_ptr< std::thread > m_thread
Definition: AMReX_BackgroundThread.H:33
void Submit(std::function< void()> &&a_f)
Definition: AMReX_BackgroundThread.cpp:38
bool m_clearing
Definition: AMReX_BackgroundThread.H:38
std::condition_variable m_job_cond
Definition: AMReX_BackgroundThread.H:35
void do_job()
Definition: AMReX_BackgroundThread.cpp:19
std::mutex m_mutx
Definition: AMReX_BackgroundThread.H:34
~BackgroundThread()
Definition: AMReX_BackgroundThread.cpp:10
std::queue< std::function< void()> > m_func
Definition: AMReX_BackgroundThread.H:37
BackgroundThread & operator=(BackgroundThread const &)=delete
BackgroundThread(BackgroundThread const &)=delete
std::condition_variable m_done_cond
Definition: AMReX_BackgroundThread.H:36
BackgroundThread(BackgroundThread &&)=delete
Definition: AMReX_Amr.cpp:49