Skip to content

Commit ebfb605

Browse files
authored
Use existing macros for atomic.wait return values. NFC (#26475)
1 parent 3f6a380 commit ebfb605

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

system/include/emscripten/atomic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ _EM_INLINE void emscripten_atomic_fence(void) {
183183

184184
#define ATOMICS_WAIT_RESULT_T int
185185

186-
// Numbering dictated by https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait
186+
// Numbering dictated by https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait:
187+
// 0 => "ok", woken by another agent.
188+
// 1 => "not-equal", loaded value != expected value
189+
// 2 => "timed-out", the timeout expired
187190
#define ATOMICS_WAIT_OK 0
188191
#define ATOMICS_WAIT_NOT_EQUAL 1
189192
#define ATOMICS_WAIT_TIMED_OUT 2

system/lib/pthread/emscripten_futex_wait.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int emscripten_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms)
136136
}
137137

138138
// -1 (or any negative number) means wait indefinitely.
139-
int64_t max_wait_ns = -1;
139+
int64_t max_wait_ns = ATOMICS_WAIT_DURATION_INFINITE;
140140
if (max_wait_ms != INFINITY) {
141141
max_wait_ns = (int64_t)(max_wait_ms*1000*1000);
142142
}
@@ -166,16 +166,12 @@ int emscripten_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms)
166166
done:
167167
emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS_WAITFUTEX, EM_THREAD_STATUS_RUNNING);
168168

169-
// memory.atomic.wait32 returns:
170-
// 0 => "ok", woken by another agent.
171-
// 1 => "not-equal", loaded value != expected value
172-
// 2 => "timed-out", the timeout expired
173-
if (ret == 1) {
169+
if (ret == ATOMICS_WAIT_NOT_EQUAL) {
174170
return -EWOULDBLOCK;
175171
}
176-
if (ret == 2) {
172+
if (ret == ATOMICS_WAIT_TIMED_OUT) {
177173
return -ETIMEDOUT;
178174
}
179-
assert(ret == 0);
175+
assert(ret == ATOMICS_WAIT_OK);
180176
return 0;
181177
}

0 commit comments

Comments
 (0)