@@ -18,22 +18,23 @@ extern void* _emscripten_main_thread_futex;
1818int _emscripten_thread_supports_atomics_wait (void );
1919
2020static int futex_wait_busy (volatile void * addr , uint32_t val , double timeout ) {
21- // Atomics.wait is not available in the main browser thread, so simulate it via busy spinning.
21+ // Atomics.wait is not available in the main browser thread, so simulate it
22+ // via busy spinning.
2223 double now = emscripten_get_now ();
2324 double end = now + timeout ;
2425
25- // Register globally which address the main thread is simulating to be
26- // waiting on. When zero, the main thread is not waiting on anything, and on
27- // nonzero, the contents of the address pointed by __emscripten_main_thread_futex
28- // tell which address the main thread is simulating its wait on.
29- // We need to be careful of recursion here: If we wait on a futex, and
30- // then call _emscripten_yield() below, that will call code that takes the
31- // proxying mutex - which can once more reach this code in a nested call. To
32- // avoid interference between the two (there is just a single
33- // __emscripten_main_thread_futex at a time), unmark ourselves before calling
26+ // Register globally which address the main thread is simulating to be waiting
27+ // on. When zero, the main thread is not waiting on anything, and on nonzero,
28+ // the contents of the address pointed by _emscripten_main_thread_futex tell
29+ // which address the main thread is simulating its wait on. We need to be
30+ // careful of recursion here: If we wait on a futex, and then call
31+ // _emscripten_yield() below, that will call code that takes the proxying
32+ // mutex - which can once more reach this code in a nested call. To avoid
33+ // interference between the two (there is just a single
34+ // _emscripten_main_thread_futex at a time), unmark ourselves before calling
3435 // the potentially-recursive call. See below for how we handle the case of our
3536 // futex being notified during the time in between when we are not set as the
36- // value of __emscripten_main_thread_futex .
37+ // value of _emscripten_main_thread_futex .
3738 void * last_addr = a_cas_p (& _emscripten_main_thread_futex , 0 , (void * )addr );
3839 // We must not have already been waiting.
3940 assert (last_addr == 0 );
@@ -68,20 +69,20 @@ static int futex_wait_busy(volatile void *addr, uint32_t val, double timeout) {
6869 //
6970 // * wait on futex A
7071 // * recurse into _emscripten_yield(),
71- // which waits on futex B. that sets the __emscripten_main_thread_futex address to
72- // futex B, and there is no longer any mention of futex A.
73- // * a worker is done with futex A. it checks __emscripten_main_thread_futex but does
74- // not see A, so it does nothing special for the main thread.
72+ // which waits on futex B. that sets the _emscripten_main_thread_futex
73+ // address to futex B, and there is no longer any mention of futex A.
74+ // * a worker is done with futex A. it checks _emscripten_main_thread_futex
75+ // but does not see A, so it does nothing special for the main thread.
7576 // * a worker is done with futex B. it flips mainThreadMutex from B
7677 // to 0, ending the wait on futex B.
77- // * we return to the wait on futex A. __emscripten_main_thread_futex is 0, but that
78- // is because of futex B being done - we can't tell from
79- // __emscripten_main_thread_futex whether A is done or not. therefore, check the
80- // memory value of the futex.
78+ // * we return to the wait on futex A. _emscripten_main_thread_futex is 0,
79+ // but that is because of futex B being done - we can't tell from
80+ // _emscripten_main_thread_futex whether A is done or not. therefore,
81+ // check the memory value of the futex.
8182 //
8283 // That case motivates the design here. Given that, checking the memory
8384 // address is also necessary for other reasons: we unset and re-set our
84- // address in __emscripten_main_thread_futex around calls to
85+ // address in _emscripten_main_thread_futex around calls to
8586 // _emscripten_yield(), and a worker could
8687 // attempt to wake us up right before/after such times.
8788 //
0 commit comments