Browse Source

MT#56374 switch from usleep to nanosleep

This allows for longer (> 1 second) sleep times reliably.

Change-Id: I054f3b5ebf499e208c3618447e7ad1b54e52bfcf
pull/1692/head
Richard Fuchs 2 years ago
parent
commit
c71a3419d1
1 changed files with 16 additions and 3 deletions
  1. +16
    -3
      daemon/helpers.c

+ 16
- 3
daemon/helpers.c View File

@ -321,6 +321,10 @@ static void thread_looper_helper(void *fp) {
#endif
static const long long warn_limit_pct = 20; // 20%
long long warn_limit_us = interval_us * warn_limit_pct / 100;
struct timespec interval_ts = {
.tv_sec = interval_us / 1000000,
.tv_nsec = (interval_us % 1000000) * 1000,
};
while (!rtpe_shutdown) {
gettimeofday(&rtpe_now, NULL);
@ -341,9 +345,18 @@ static void thread_looper_helper(void *fp) {
if (ret == TLA_BREAK)
break;
thread_cancel_enable();
usleep(interval_us);
thread_cancel_disable();
struct timespec sleeptime = interval_ts;
struct timespec remtime;
while (true) {
thread_cancel_enable();
int res = nanosleep(&sleeptime, &remtime);
thread_cancel_disable();
if (res == -1 && errno == EINTR) {
sleeptime = remtime;
continue;
}
break;
}
}
}


Loading…
Cancel
Save