Skip to content
Snippets Groups Projects
Commit 8d49f8dc authored by Pieter Donker's avatar Pieter Donker
Browse files

L2SDP-499, changes to prevent 100% load after returning from sleep/hibernate.

parent affaa157
No related branches found
No related tags found
1 merge request!28Resolve L2SDP-489
...@@ -76,7 +76,19 @@ void monitor() ...@@ -76,7 +76,19 @@ void monitor()
while (ServerRunning) { while (ServerRunning) {
struct timespec current_time_timespec;
clock_gettime(CLOCK_REALTIME, (struct timespec *)&current_time_timespec);
SD.t0.tv_sec = SD.t0.tv_sec + SD.timetick; // specify next position in time SD.t0.tv_sec = SD.t0.tv_sec + SD.timetick; // specify next position in time
if (SD.t0.tv_sec < current_time_timespec.tv_sec) {
// skip ahead if we already are beyond the next tick.
// this prevents us from trying to catch up if the host system
// was in hibernation or this process was otherwise suspended.
// this means that SD.uptime will reflect the number of seconds
// this process was actually running, and now - SD.start_time
// reflects the wall-clock time that passed since start.
SD.t0.tv_sec = current_time_timespec.tv_sec + SD.timetick;
}
SD.t0.tv_nsec = 10000000L; // 0..999999999 // offset 10ms in a new second SD.t0.tv_nsec = 10000000L; // 0..999999999 // offset 10ms in a new second
pthread_mutex_lock(&SD.newpoint_lock); pthread_mutex_lock(&SD.newpoint_lock);
pthread_cond_timedwait(&SD.newpoint_cond, &SD.newpoint_lock, (const struct timespec *)&SD.t0); pthread_cond_timedwait(&SD.newpoint_cond, &SD.newpoint_lock, (const struct timespec *)&SD.t0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment