Skip to content

Commit 307b959

Browse files
author
Chris Warren-Smith
committed
COMMON: fix negative usleep when over-slept in event handler
1 parent 2e33f42 commit 307b959

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/platform/android/jni/runtime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,9 @@ void Runtime::pause(int timeout) {
892892
delete event;
893893
}
894894
slept = dev_get_millisecond_count() - now;
895-
if (timeout - slept > WAIT_INTERVAL) {
895+
if (slept > timeout) {
896+
break;
897+
} else if (timeout - slept > WAIT_INTERVAL) {
896898
usleep(WAIT_INTERVAL * 1000);
897899
} else {
898900
usleep((timeout - slept) * 1000);

src/platform/console/device.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ void dev_delay(uint32_t timeout) {
451451
break;
452452
}
453453
slept = dev_get_millisecond_count() - now;
454-
if (timeout - slept > WAIT_INTERVAL) {
454+
if (slept > timeout) {
455+
break;
456+
} else if (timeout - slept > WAIT_INTERVAL) {
455457
usleep(WAIT_INTERVAL * 1000);
456458
} else {
457459
usleep((timeout - slept) * 1000);

src/platform/sdl/runtime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ void Runtime::pause(int timeout) {
429429
delete event;
430430
}
431431
slept = dev_get_millisecond_count() - now;
432-
if (timeout - slept > WAIT_INTERVAL) {
432+
if (slept > timeout) {
433+
break;
434+
} else if (timeout - slept > WAIT_INTERVAL) {
433435
usleep(WAIT_INTERVAL * 1000);
434436
} else {
435437
usleep((timeout - slept) * 1000);

0 commit comments

Comments
 (0)