@@ -382,22 +382,24 @@ static CallQueue* GetOrAllocateQueue(void* target) {
382
382
}
383
383
384
384
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 ;
397
386
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 ;
401
403
}
402
404
403
405
EMSCRIPTEN_RESULT emscripten_wait_for_call_i (
0 commit comments