From e8038416e72616a6c53af2fc48ac7c000a82e4c8 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 3 Jul 2017 14:02:03 +0200 Subject: [PATCH] Sleep more lenient --- libs/core/linux.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/core/linux.cpp b/libs/core/linux.cpp index be438461..0990cbe1 100644 --- a/libs/core/linux.cpp +++ b/libs/core/linux.cpp @@ -92,21 +92,25 @@ void stopUser() { pthread_mutex_unlock(&execMutex); } -void sleep_ms(uint32_t ms) { - stopUser(); - +void sleep_core_ms(uint32_t ms) { struct timespec ts; ts.tv_sec = ms / 1000; ts.tv_nsec = (ms % 1000) * 1000000; while (nanosleep(&ts, &ts)) ; +} - startUser(); +void sleep_ms(uint32_t ms) { + if (execThread == pthread_self()) { + stopUser(); + sleep_core_ms(ms); + startUser(); + } else { + sleep_core_ms(ms); + } } void sleep_us(uint64_t us) { - checkUserMode(); - if (us > 10000) { sleep_ms(us / 1000); }