doc: Switch scheduler to doxygen comments

This commit is contained in:
MarcoFalke 2020-05-28 09:03:11 -04:00
parent fac43f9889
commit fa3d41b5ab
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

View File

@ -12,23 +12,23 @@
#include <sync.h> #include <sync.h>
// /**
// Simple class for background tasks that should be run * Simple class for background tasks that should be run
// periodically or once "after a while" * periodically or once "after a while"
// *
// Usage: * Usage:
// *
// CScheduler* s = new CScheduler(); * CScheduler* s = new CScheduler();
// s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); // Assuming a: void doSomething() { } * s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); // Assuming a: void doSomething() { }
// s->scheduleFromNow([=] { this->func(argument); }, std::chrono::milliseconds{3}); * s->scheduleFromNow([=] { this->func(argument); }, std::chrono::milliseconds{3});
// std::thread* t = new std::thread([&] { s->serviceQueue(); }); * 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: * ... then at program shutdown, make sure to call stop() to clean up the thread(s) running serviceQueue:
// s->stop(); * s->stop();
// t->join(); * t->join();
// delete t; * delete t;
// delete s; // Must be done after thread is interrupted/joined. * delete s; // Must be done after thread is interrupted/joined.
// */
class CScheduler class CScheduler
{ {
public: public:
@ -37,7 +37,7 @@ public:
typedef std::function<void()> Function; typedef std::function<void()> Function;
// Call func at/after time t /** Call func at/after time t */
void schedule(Function f, std::chrono::system_clock::time_point t); void schedule(Function f, std::chrono::system_clock::time_point t);
/** Call f once after the delta has passed */ /** Call f once after the delta has passed */
@ -61,8 +61,10 @@ public:
*/ */
void MockForward(std::chrono::seconds delta_seconds); void MockForward(std::chrono::seconds delta_seconds);
// Services the queue 'forever'. Should be run in a thread, /**
// and interrupted using boost::interrupt_thread * Services the queue 'forever'. Should be run in a thread,
* and interrupted using boost::interrupt_thread
*/
void serviceQueue(); void serviceQueue();
/** Tell any threads running serviceQueue to stop as soon as the current task is done */ /** Tell any threads running serviceQueue to stop as soon as the current task is done */
@ -78,12 +80,14 @@ public:
newTaskScheduled.notify_all(); newTaskScheduled.notify_all();
} }
// Returns number of tasks waiting to be serviced, /**
// and first and last task times * Returns number of tasks waiting to be serviced,
* and first and last task times
*/
size_t getQueueInfo(std::chrono::system_clock::time_point &first, size_t getQueueInfo(std::chrono::system_clock::time_point &first,
std::chrono::system_clock::time_point &last) const; std::chrono::system_clock::time_point &last) const;
// Returns true if there are threads actively running in serviceQueue() /** Returns true if there are threads actively running in serviceQueue() */
bool AreThreadsServicingQueue() const; bool AreThreadsServicingQueue() const;
private: private:
@ -128,8 +132,10 @@ public:
*/ */
void AddToProcessQueue(std::function<void ()> func); void AddToProcessQueue(std::function<void ()> func);
// Processes all remaining queue members on the calling thread, blocking until queue is empty /**
// Must be called after the CScheduler has no remaining processing threads! * Processes all remaining queue members on the calling thread, blocking until queue is empty
* Must be called after the CScheduler has no remaining processing threads!
*/
void EmptyQueue(); void EmptyQueue();
size_t CallbacksPending(); size_t CallbacksPending();