mirror of
https://github.com/janet-lang/janet
synced 2025-01-12 00:20:26 +00:00
Add support for atomic loads in Janet's atomic abstraction.
This commit is contained in:
parent
e74365fe38
commit
609b629c22
@ -509,6 +509,14 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
||||
#endif
|
||||
}
|
||||
|
||||
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
|
||||
#ifdef JANET_WINDOWS
|
||||
return InterlockedOr(x, 0);
|
||||
#else
|
||||
return __atomic_load_n(x, __ATOMIC_ACQUIRE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Some definitions for function-like macros */
|
||||
|
||||
JANET_API JanetStructHead *(janet_struct_head)(JanetStruct st) {
|
||||
|
@ -1284,7 +1284,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout);
|
||||
int janet_loop_done(void) {
|
||||
return !((janet_vm.spawn.head != janet_vm.spawn.tail) ||
|
||||
janet_vm.tq_count ||
|
||||
janet_vm.listener_count);
|
||||
janet_atomic_load(&janet_vm.listener_count));
|
||||
}
|
||||
|
||||
JanetFiber *janet_loop1(void) {
|
||||
@ -1346,7 +1346,7 @@ JanetFiber *janet_loop1(void) {
|
||||
}
|
||||
|
||||
/* Poll for events */
|
||||
if (janet_vm.tq_count || janet_vm.listener_count) {
|
||||
if (janet_vm.tq_count || janet_atomic_load(&janet_vm.listener_count)) {
|
||||
JanetTimeout to;
|
||||
memset(&to, 0, sizeof(to));
|
||||
int has_timeout;
|
||||
@ -1365,7 +1365,7 @@ JanetFiber *janet_loop1(void) {
|
||||
break;
|
||||
}
|
||||
/* Run polling implementation only if pending timeouts or pending events */
|
||||
if (janet_vm.tq_count || janet_vm.listener_count) {
|
||||
if (janet_vm.tq_count || janet_atomic_load(&janet_vm.listener_count)) {
|
||||
janet_loop1_impl(has_timeout, to.when);
|
||||
}
|
||||
}
|
||||
|
@ -647,6 +647,7 @@ typedef int32_t JanetAtomicInt;
|
||||
#endif
|
||||
JANET_API JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x);
|
||||
JANET_API JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x);
|
||||
JANET_API JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x);
|
||||
|
||||
/* We provide three possible implementations of Janets. The preferred
|
||||
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
||||
|
Loading…
Reference in New Issue
Block a user