Skip to content
Snippets Groups Projects
Commit 23653f9f authored by Julian Oes's avatar Julian Oes Committed by Lorenz Meier
Browse files

lockstep_scheduler: fix return value, remove errno

The API of cond_timedwait was wrong. It used return -1 and set errno
instead of returning the error as specified for pthread_cond_timedwait
which it tries to mock.
parent 0d0a5568
No related branches found
No related tags found
No related merge requests found
......@@ -57,8 +57,7 @@ int LockstepScheduler::cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *loc
// The time has already passed.
if (time_us <= time_us_) {
errno = ETIMEDOUT;
return -1;
return ETIMEDOUT;
}
new_timed_wait = std::make_shared<TimedWait>();
......@@ -80,8 +79,7 @@ int LockstepScheduler::cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *loc
std::lock_guard<std::mutex> lock_timed_waits(timed_waits_mutex_);
if (result == 0 && new_timed_wait->timeout) {
errno = ETIMEDOUT;
result = -1;
result = ETIMEDOUT;
}
new_timed_wait->done = true;
......@@ -104,9 +102,8 @@ int LockstepScheduler::usleep_until(uint64_t time_us)
int result = cond_timedwait(&cond, &lock, time_us);
if (result == -1 && errno == ETIMEDOUT) {
if (result == ETIMEDOUT) {
// This is expected because we never notified to the condition.
errno = 0;
result = 0;
}
......
......@@ -34,8 +34,7 @@ void test_condition_timing_out()
// Use a thread to wait for condition while we already have the lock.
// This ensures the synchronization happens in the right order.
std::thread thread([&ls, &cond, &lock, &should_have_timed_out]() {
assert(ls.cond_timedwait(&cond, &lock, some_time_us + 1000) == -1);
assert(errno == ETIMEDOUT);
assert(ls.cond_timedwait(&cond, &lock, some_time_us + 1000) == ETIMEDOUT);
assert(should_have_timed_out);
// It should be re-locked afterwards, so we should be able to unlock it.
assert(pthread_mutex_unlock(&lock) == 0);
......@@ -139,7 +138,7 @@ public:
else if (timeout_reached) {
is_done_ = true;
thread_->join();
assert(result_ == -1);
assert(result_ == ETIMEDOUT);
}
}
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment