Skip to content

Commit d78e59f

Browse files
committed
Revert emscripten_wait_for_call_v change
1 parent 190b6b9 commit d78e59f

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
@@ -382,22 +382,24 @@ static CallQueue* GetOrAllocateQueue(void* target) {
382382
}
383383

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

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

403405
EMSCRIPTEN_RESULT emscripten_wait_for_call_i(

0 commit comments

Comments
 (0)