File tree Expand file tree Collapse file tree 3 files changed +15
-19
lines changed Expand file tree Collapse file tree 3 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -68,18 +68,6 @@ void CScheduler::serviceQueue()
68
68
newTaskScheduled.notify_one ();
69
69
}
70
70
71
- void CScheduler::stop (bool drain)
72
- {
73
- {
74
- LOCK (newTaskMutex);
75
- if (drain)
76
- stopWhenEmpty = true ;
77
- else
78
- stopRequested = true ;
79
- }
80
- newTaskScheduled.notify_all ();
81
- }
82
-
83
71
void CScheduler::schedule (CScheduler::Function f, std::chrono::system_clock::time_point t)
84
72
{
85
73
{
Original file line number Diff line number Diff line change @@ -65,10 +65,18 @@ class CScheduler
65
65
// and interrupted using boost::interrupt_thread
66
66
void serviceQueue ();
67
67
68
- // Tell any threads running serviceQueue to stop as soon as they're
69
- // done servicing whatever task they're currently servicing (drain=false)
70
- // or when there is no work left to be done (drain=true)
71
- void stop (bool drain=false );
68
+ /* * Tell any threads running serviceQueue to stop as soon as the current task is done */
69
+ void stop ()
70
+ {
71
+ WITH_LOCK (newTaskMutex, stopRequested = true );
72
+ newTaskScheduled.notify_all ();
73
+ }
74
+ /* * Tell any threads running serviceQueue to stop when there is no work left to be done */
75
+ void StopWhenDrained ()
76
+ {
77
+ WITH_LOCK (newTaskMutex, stopWhenEmpty = true );
78
+ newTaskScheduled.notify_all ();
79
+ }
72
80
73
81
// Returns number of tasks waiting to be serviced,
74
82
// and first and last task times
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(manythreads)
89
89
}
90
90
91
91
// Drain the task queue then exit threads
92
- microTasks.stop ( true );
92
+ microTasks.StopWhenDrained ( );
93
93
microThreads.join_all (); // ... wait until all the threads are done
94
94
95
95
int counterSum = 0 ;
@@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
155
155
}
156
156
157
157
// finish up
158
- scheduler.stop ( true );
158
+ scheduler.StopWhenDrained ( );
159
159
threads.join_all ();
160
160
161
161
BOOST_CHECK_EQUAL (counter1, 100 );
@@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE(mockforward)
186
186
scheduler.MockForward (std::chrono::minutes{5 });
187
187
188
188
// ensure scheduler has chance to process all tasks queued for before 1 ms from now.
189
- scheduler.scheduleFromNow ([&scheduler] { scheduler.stop (false ); }, std::chrono::milliseconds{1 });
189
+ scheduler.scheduleFromNow ([&scheduler] { scheduler.stop (); }, std::chrono::milliseconds{1 });
190
190
scheduler_thread.join ();
191
191
192
192
// check that the queue only has one job remaining
You can’t perform that action at this time.
0 commit comments