Skip to content

Commit 6d77f4d

Browse files
committed
Revert emscripten_wait_for_call_v change
1 parent ecb6664 commit 6d77f4d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

system/lib/pthread/library_pthread.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,24 @@ static CallQueue* GetOrAllocateQueue(void* target) {
384384
}
385385

386386
EMSCRIPTEN_RESULT emscripten_wait_for_call_v(em_queued_call* call, double timeoutMSecs) {
387-
int done = atomic_load(&call->operationDone);
388-
if (done) return EMSCRIPTEN_RESULT_SUCCESS;
389-
390-
emscripten_set_current_thread_status(EM_THREAD_STATUS_WAITPROXY);
391-
392-
double timeoutUntilTime = emscripten_get_now() + timeoutMSecs;
393-
do {
394-
emscripten_futex_wait(&call->operationDone, 0, timeoutMSecs);
395-
done = atomic_load(&call->operationDone);
396-
397-
timeoutMSecs = timeoutUntilTime - emscripten_get_now();
398-
} while (!done && timeoutMSecs > 0);
387+
int r;
399388

400-
emscripten_set_current_thread_status(EM_THREAD_STATUS_RUNNING);
401-
402-
return done ? EMSCRIPTEN_RESULT_SUCCESS : EMSCRIPTEN_RESULT_TIMED_OUT;
389+
int done = atomic_load(&call->operationDone);
390+
if (!done) {
391+
double now = emscripten_get_now();
392+
double waitEndTime = now + timeoutMSecs;
393+
emscripten_set_current_thread_status(EM_THREAD_STATUS_WAITPROXY);
394+
while (!done && now < waitEndTime) {
395+
r = emscripten_futex_wait(&call->operationDone, 0, waitEndTime - now);
396+
done = atomic_load(&call->operationDone);
397+
now = emscripten_get_now();
398+
}
399+
emscripten_set_current_thread_status(EM_THREAD_STATUS_RUNNING);
400+
}
401+
if (done)
402+
return EMSCRIPTEN_RESULT_SUCCESS;
403+
else
404+
return EMSCRIPTEN_RESULT_TIMED_OUT;
403405
}
404406

405407
EMSCRIPTEN_RESULT emscripten_wait_for_call_i(

0 commit comments

Comments
 (0)