From ce091fd4e400c9e0d20bc2cf86dc8e8768b44bcf Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 2 Sep 2021 17:41:33 -0400 Subject: [PATCH] [client] main: correctly handle EINTR from nanosleep Previously, all progress made during sleep is reset, so if the thread keeps getting interrupted before the sleep finishes, the sleep will never complete. --- client/src/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index b2b91a7a..f55a0576 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -349,7 +349,7 @@ static int cursorThread(void * unused) lgSignalEvent(g_state.frameEvent); } - const struct timespec req = + struct timespec req = { .tv_sec = 0, .tv_nsec = g_params.cursorPollInterval * 1000L @@ -357,11 +357,14 @@ static int cursorThread(void * unused) struct timespec rem; while(nanosleep(&req, &rem) < 0) + { if (errno != -EINTR) { DEBUG_ERROR("nanosleep failed"); break; } + req = rem; + } continue; } @@ -499,7 +502,7 @@ int main_frameThread(void * unused) { if (status == LGMP_ERR_QUEUE_EMPTY) { - const struct timespec req = + struct timespec req = { .tv_sec = 0, .tv_nsec = g_params.framePollInterval * 1000L @@ -507,11 +510,14 @@ int main_frameThread(void * unused) struct timespec rem; while(nanosleep(&req, &rem) < 0) + { if (errno != -EINTR) { DEBUG_ERROR("nanosleep failed"); break; } + req = rem; + } continue; }