15
15
16
16
BOOST_AUTO_TEST_SUITE (scheduler_tests)
17
17
18
- static void microTask(CScheduler& s, std::mutex& mutex, int & counter, int delta, std::chrono::system_clock ::time_point rescheduleTime)
18
+ static void microTask(CScheduler& s, std::mutex& mutex, int & counter, int delta, std::chrono::steady_clock ::time_point rescheduleTime)
19
19
{
20
20
{
21
21
std::lock_guard<std::mutex> lock (mutex);
22
22
counter += delta;
23
23
}
24
- std::chrono::system_clock::time_point noTime = std::chrono::system_clock ::time_point::min ();
24
+ auto noTime = std::chrono::steady_clock ::time_point::min ();
25
25
if (rescheduleTime != noTime) {
26
26
CScheduler::Function f = std::bind (µTask, std::ref (s), std::ref (mutex), std::ref (counter), -delta + 1 , noTime);
27
27
s.schedule (f, rescheduleTime);
@@ -49,15 +49,15 @@ BOOST_AUTO_TEST_CASE(manythreads)
49
49
auto randomMsec = [](FastRandomContext& rc) -> int { return -11 + (int )rc.randrange (1012 ); }; // [-11, 1000]
50
50
auto randomDelta = [](FastRandomContext& rc) -> int { return -1000 + (int )rc.randrange (2001 ); }; // [-1000, 1000]
51
51
52
- std::chrono::system_clock::time_point start = std::chrono::system_clock ::now ();
53
- std::chrono::system_clock::time_point now = start;
54
- std::chrono::system_clock ::time_point first, last;
52
+ auto start = std::chrono::steady_clock ::now ();
53
+ auto now = start;
54
+ std::chrono::steady_clock ::time_point first, last;
55
55
size_t nTasks = microTasks.getQueueInfo (first, last);
56
56
BOOST_CHECK (nTasks == 0 );
57
57
58
58
for (int i = 0 ; i < 100 ; ++i) {
59
- std::chrono::system_clock::time_point t = now + std::chrono::microseconds (randomMsec (rng));
60
- std::chrono::system_clock::time_point tReschedule = now + std::chrono::microseconds (500 + randomMsec (rng));
59
+ auto t = now + std::chrono::microseconds (randomMsec (rng));
60
+ auto tReschedule = now + std::chrono::microseconds (500 + randomMsec (rng));
61
61
int whichCounter = zeroToNine (rng);
62
62
CScheduler::Function f = std::bind (µTask, std::ref (microTasks),
63
63
std::ref (counterMutex[whichCounter]), std::ref (counter[whichCounter]),
@@ -75,14 +75,14 @@ BOOST_AUTO_TEST_CASE(manythreads)
75
75
microThreads.emplace_back (std::bind (&CScheduler::serviceQueue, µTasks));
76
76
77
77
UninterruptibleSleep (std::chrono::microseconds{600 });
78
- now = std::chrono::system_clock ::now ();
78
+ now = std::chrono::steady_clock ::now ();
79
79
80
80
// More threads and more tasks:
81
81
for (int i = 0 ; i < 5 ; i++)
82
82
microThreads.emplace_back (std::bind (&CScheduler::serviceQueue, µTasks));
83
83
for (int i = 0 ; i < 100 ; i++) {
84
- std::chrono::system_clock::time_point t = now + std::chrono::microseconds (randomMsec (rng));
85
- std::chrono::system_clock::time_point tReschedule = now + std::chrono::microseconds (500 + randomMsec (rng));
84
+ auto t = now + std::chrono::microseconds (randomMsec (rng));
85
+ auto tReschedule = now + std::chrono::microseconds (500 + randomMsec (rng));
86
86
int whichCounter = zeroToNine (rng);
87
87
CScheduler::Function f = std::bind (µTask, std::ref (microTasks),
88
88
std::ref (counterMutex[whichCounter]), std::ref (counter[whichCounter]),
@@ -111,8 +111,8 @@ BOOST_AUTO_TEST_CASE(wait_until_past)
111
111
Mutex mtx;
112
112
WAIT_LOCK (mtx, lock);
113
113
114
- const auto no_wait= [&](const std::chrono::seconds& d) {
115
- return condvar.wait_until (lock, std::chrono::system_clock ::now () - d);
114
+ const auto no_wait = [&](const std::chrono::seconds& d) {
115
+ return condvar.wait_until (lock, std::chrono::steady_clock ::now () - d);
116
116
};
117
117
118
118
BOOST_CHECK (std::cv_status::timeout == no_wait (std::chrono::seconds{1 }));
@@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(mockforward)
183
183
scheduler.scheduleFromNow (dummy, std::chrono::minutes{8 });
184
184
185
185
// check taskQueue
186
- std::chrono::system_clock ::time_point first, last;
186
+ std::chrono::steady_clock ::time_point first, last;
187
187
size_t num_tasks = scheduler.getQueueInfo (first, last);
188
188
BOOST_CHECK_EQUAL (num_tasks, 3ul );
189
189
@@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(mockforward)
204
204
BOOST_CHECK_EQUAL (counter, 2 );
205
205
206
206
// check that the time of the remaining job has been updated
207
- std::chrono::system_clock::time_point now = std::chrono::system_clock ::now ();
207
+ auto now = std::chrono::steady_clock ::now ();
208
208
int delta = std::chrono::duration_cast<std::chrono::seconds>(first - now).count ();
209
209
// should be between 2 & 3 minutes from now
210
210
BOOST_CHECK (delta > 2 *60 && delta < 3 *60 );
0 commit comments