| Simple class for background tasks that
| should be run periodically or once “after
| a while”
|
| Usage:
|
| ———–
| @code
|
| CScheduler* s = new CScheduler();
| s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); // Assuming a: c_void doSomething() { }
| s->scheduleFromNow([=] { this->func(argument); }, std::chrono::milliseconds{3});
| std::thread* t = new std::thread(& { s->serviceQueue(); });
|
| … then at program shutdown, make sure to call stop() to clean up the thread(s) running serviceQueue:
| s->stop();
| t->join();
| delete t;
| delete s; // Must be done after thread is interrupted/joined.
|
| Class used by CScheduler clients which
| may schedule multiple jobs which are
| required to be run serially.
|
| Jobs may not be run on the same thread,
| but no two jobs will be executed at the
| same time and memory will be release-acquire
| consistent (the scheduler will internally
| do an acquire before invoking a callback
| as well as a release at the end).
|
| In practice this means that a callback
|
| B() will be able to observe all of the
| effects of callback A() which executed
| before it.
|