Update janet_interpreter_interrupt to use new atomics

This commit is contained in:
Calvin Rose 2023-10-01 10:52:05 -05:00
parent af7ed4322e
commit 51a75e1872
2 changed files with 3 additions and 11 deletions

View File

@ -62,18 +62,10 @@ void janet_vm_load(JanetVM *from) {
* use NULL to interrupt the current VM when convenient */ * use NULL to interrupt the current VM when convenient */
void janet_interpreter_interrupt(JanetVM *vm) { void janet_interpreter_interrupt(JanetVM *vm) {
vm = vm ? vm : &janet_vm; vm = vm ? vm : &janet_vm;
#ifdef JANET_WINDOWS janet_atomic_inc(&vm->auto_suspend);
InterlockedIncrement(&vm->auto_suspend);
#else
__atomic_add_fetch(&vm->auto_suspend, 1, __ATOMIC_RELAXED);
#endif
} }
void janet_interpreter_interrupt_handled(JanetVM *vm) { void janet_interpreter_interrupt_handled(JanetVM *vm) {
vm = vm ? vm : &janet_vm; vm = vm ? vm : &janet_vm;
#ifdef JANET_WINDOWS janet_atomic_dec(&vm->auto_suspend);
InterlockedDecrement(&vm->auto_suspend);
#else
__atomic_add_fetch(&vm->auto_suspend, -1, __ATOMIC_RELAXED);
#endif
} }

View File

@ -89,7 +89,7 @@ struct JanetVM {
/* If this flag is true, suspend on function calls and backwards jumps. /* If this flag is true, suspend on function calls and backwards jumps.
* When this occurs, this flag will be reset to 0. */ * When this occurs, this flag will be reset to 0. */
volatile int32_t auto_suspend; volatile JanetAtomicInt auto_suspend;
/* The current running fiber on the current thread. /* The current running fiber on the current thread.
* Set and unset by functions in vm.c */ * Set and unset by functions in vm.c */