[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.
This commit is contained in:
Quantum 2021-09-02 17:41:33 -04:00 committed by Geoffrey McRae
parent 49725c9ea4
commit ce091fd4e4

View File

@ -349,7 +349,7 @@ static int cursorThread(void * unused)
lgSignalEvent(g_state.frameEvent); lgSignalEvent(g_state.frameEvent);
} }
const struct timespec req = struct timespec req =
{ {
.tv_sec = 0, .tv_sec = 0,
.tv_nsec = g_params.cursorPollInterval * 1000L .tv_nsec = g_params.cursorPollInterval * 1000L
@ -357,11 +357,14 @@ static int cursorThread(void * unused)
struct timespec rem; struct timespec rem;
while(nanosleep(&req, &rem) < 0) while(nanosleep(&req, &rem) < 0)
{
if (errno != -EINTR) if (errno != -EINTR)
{ {
DEBUG_ERROR("nanosleep failed"); DEBUG_ERROR("nanosleep failed");
break; break;
} }
req = rem;
}
continue; continue;
} }
@ -499,7 +502,7 @@ int main_frameThread(void * unused)
{ {
if (status == LGMP_ERR_QUEUE_EMPTY) if (status == LGMP_ERR_QUEUE_EMPTY)
{ {
const struct timespec req = struct timespec req =
{ {
.tv_sec = 0, .tv_sec = 0,
.tv_nsec = g_params.framePollInterval * 1000L .tv_nsec = g_params.framePollInterval * 1000L
@ -507,11 +510,14 @@ int main_frameThread(void * unused)
struct timespec rem; struct timespec rem;
while(nanosleep(&req, &rem) < 0) while(nanosleep(&req, &rem) < 0)
{
if (errno != -EINTR) if (errno != -EINTR)
{ {
DEBUG_ERROR("nanosleep failed"); DEBUG_ERROR("nanosleep failed");
break; break;
} }
req = rem;
}
continue; continue;
} }