Skip to content

Commit 16fb220

Browse files
committed
Fix references to _emscripten_main_thread_futex in comments. NFC
1 parent c0c97c6 commit 16fb220

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

system/lib/pthread/emscripten_futex_wait.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ extern void* _emscripten_main_thread_futex;
1818
int _emscripten_thread_supports_atomics_wait(void);
1919

2020
static 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
//

system/lib/pthread/emscripten_futex_wake.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ int emscripten_futex_wake(volatile void *addr, int count) {
2525
return 0;
2626
}
2727

28-
// See if main thread is waiting on this address? If so, wake it up by resetting its wake location to zero.
29-
// Note that this is not a fair procedure, since we always wake main thread first before any workers, so
28+
// See if main thread is waiting on this address? If so, wake it up by
29+
// resetting its wake location to zero. Note that this is not a fair
30+
// procedure, since we always wake main thread first before any workers, so
3031
// this scheme does not adhere to real queue-based waiting.
3132
int main_thread_woken = 0;
3233
if (a_cas_p(&_emscripten_main_thread_futex, (void*)addr, 0) == addr) {
3334
// The main browser thread must never try to wake itself up!
3435
assert(!emscripten_is_main_browser_thread());
35-
if (count != INT_MAX)
36-
{
36+
if (count != INT_MAX) {
3737
--count;
3838
main_thread_woken = 1;
3939
if (count <= 0) {

0 commit comments

Comments
 (0)