@@ -384,22 +384,24 @@ static CallQueue* GetOrAllocateQueue(void* target) {
384
384
}
385
385
386
386
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 ;
399
388
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 ;
403
405
}
404
406
405
407
EMSCRIPTEN_RESULT emscripten_wait_for_call_i (
0 commit comments