30 class ProcessingHandler
33 ProcessingHandler() {}
36 if (async_thread.joinable())
41 bool is_processing =
false;
42 std::mutex is_processing_mtx;
49 std::thread async_thread;
57 is_processing_mtx.lock();
59 is_processing_mtx.unlock();
61 is_processing_mtx.lock();
62 is_processing =
false;
63 is_processing_mtx.unlock();
72 is_processing_mtx.lock();
74 is_processing_mtx.unlock();
82 is_processing_mtx.lock();
83 if (is_processing && async_thread.joinable())
85 printf(
"ALREADY PROCESSING!!!!\n");
86 is_processing_mtx.unlock();
89 is_processing_mtx.unlock();
95 catch (std::exception &e)
99 is_processing_mtx.lock();
100 is_processing =
true;
101 is_processing_mtx.unlock();
102 auto fun = [
this]() {
process(); };
103 async_thread = std::thread(fun);
106 static std::string getID();
107 static std::shared_ptr<Handler> getInstance();
void set_is_processing(bool v)
Set the processing status externally, to force waiting before starting a new thread.
Definition processing_handler.h:70
void process()
Performing processing. This is not multi-threaded, intended to call it externally.
Definition processing_handler.h:55
virtual void do_process()=0
Actual processing function to be implemented by the child class.
void asyncProcess()
Perform processing asynchronously, in a thread.
Definition processing_handler.h:80