@@ -18,18 +18,19 @@ 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
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
3334 // _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
@@ -68,16 +69,16 @@ 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
0 commit comments