12
12
13
13
#include < sync.h>
14
14
15
- //
16
- // Simple class for background tasks that should be run
17
- // periodically or once "after a while"
18
- //
19
- // Usage:
20
- //
21
- // CScheduler* s = new CScheduler();
22
- // s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); // Assuming a: void doSomething() { }
23
- // s->scheduleFromNow([=] { this->func(argument); }, std::chrono::milliseconds{3});
24
- // std::thread* t = new std::thread([&] { s->serviceQueue(); });
25
- //
26
- // ... then at program shutdown, make sure to call stop() to clean up the thread(s) running serviceQueue:
27
- // s->stop();
28
- // t->join();
29
- // delete t;
30
- // delete s; // Must be done after thread is interrupted/joined.
31
- / /
15
+ /* *
16
+ * Simple class for background tasks that should be run
17
+ * periodically or once "after a while"
18
+ *
19
+ * Usage:
20
+ *
21
+ * CScheduler* s = new CScheduler();
22
+ * s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); // Assuming a: void doSomething() { }
23
+ * s->scheduleFromNow([=] { this->func(argument); }, std::chrono::milliseconds{3});
24
+ * std::thread* t = new std::thread([&] { s->serviceQueue(); });
25
+ *
26
+ * ... then at program shutdown, make sure to call stop() to clean up the thread(s) running serviceQueue:
27
+ * s->stop();
28
+ * t->join();
29
+ * delete t;
30
+ * delete s; // Must be done after thread is interrupted/joined.
31
+ * /
32
32
class CScheduler
33
33
{
34
34
public:
@@ -37,7 +37,7 @@ class CScheduler
37
37
38
38
typedef std::function<void ()> Function;
39
39
40
- // Call func at/after time t
40
+ /* * Call func at/after time t */
41
41
void schedule (Function f, std::chrono::system_clock::time_point t);
42
42
43
43
/* * Call f once after the delta has passed */
@@ -61,8 +61,10 @@ class CScheduler
61
61
*/
62
62
void MockForward (std::chrono::seconds delta_seconds);
63
63
64
- // Services the queue 'forever'. Should be run in a thread,
65
- // and interrupted using boost::interrupt_thread
64
+ /* *
65
+ * Services the queue 'forever'. Should be run in a thread,
66
+ * and interrupted using boost::interrupt_thread
67
+ */
66
68
void serviceQueue ();
67
69
68
70
/* * Tell any threads running serviceQueue to stop as soon as the current task is done */
@@ -78,12 +80,14 @@ class CScheduler
78
80
newTaskScheduled.notify_all ();
79
81
}
80
82
81
- // Returns number of tasks waiting to be serviced,
82
- // and first and last task times
83
+ /* *
84
+ * Returns number of tasks waiting to be serviced,
85
+ * and first and last task times
86
+ */
83
87
size_t getQueueInfo (std::chrono::system_clock::time_point &first,
84
88
std::chrono::system_clock::time_point &last) const ;
85
89
86
- // Returns true if there are threads actively running in serviceQueue()
90
+ /* * Returns true if there are threads actively running in serviceQueue() */
87
91
bool AreThreadsServicingQueue () const ;
88
92
89
93
private:
@@ -128,8 +132,10 @@ class SingleThreadedSchedulerClient {
128
132
*/
129
133
void AddToProcessQueue (std::function<void ()> func);
130
134
131
- // Processes all remaining queue members on the calling thread, blocking until queue is empty
132
- // Must be called after the CScheduler has no remaining processing threads!
135
+ /* *
136
+ * Processes all remaining queue members on the calling thread, blocking until queue is empty
137
+ * Must be called after the CScheduler has no remaining processing threads!
138
+ */
133
139
void EmptyQueue ();
134
140
135
141
size_t CallbacksPending ();
0 commit comments