Skip to content

Commit

Permalink
update wake-up time modification
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulero committed Feb 19, 2021
1 parent 40d98fe commit f216964
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/libYARP_os/src/yarp/os/NetworkClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ bool NetworkClock::Private::read(ConnectionReader& reader)
}

timeMutex.lock();
bool previousTimestampAvailable = initted;
double oldTime = _time;
sec = bot.get(0).asInt32();
nsec = bot.get(1).asInt32();
_time = sec + (nsec * 1e-9);
initted = true;
timeMutex.unlock();

// If the clock time has been reset (i.e. it jumped back in time)
// release all the threads currently waiting
bool clockResetDetected = previousTimestampAvailable && (_time < oldTime);
listMutex.lock();
auto waiter_it = waiters->begin();
while (waiter_it != waiters->end()) {
if (waiter_it->first - _time < 1E-12 || clockResetDetected) {
// Update the wake-up time. In case of a time reset it closes the gap between the waiter and _time.
waiter_it->first = _time + (waiter_it->first - oldTime);

while (waiter_it != waiters->end())
{
if (waiter_it->first - _time < 1E-12) {
Semaphore* waiterSemaphore = waiter_it->second;
waiter_it = waiters->erase(waiter_it);
if (waiterSemaphore != nullptr) {
Expand Down

0 comments on commit f216964

Please sign in to comment.