mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Add support for atomic loads in Janet's atomic abstraction.
This commit is contained in:
		| @@ -509,6 +509,14 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) { | |||||||
| #endif | #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 */ | /* Some definitions for function-like macros */ | ||||||
|  |  | ||||||
| JANET_API JanetStructHead *(janet_struct_head)(JanetStruct st) { | 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) { | int janet_loop_done(void) { | ||||||
|     return !((janet_vm.spawn.head != janet_vm.spawn.tail) || |     return !((janet_vm.spawn.head != janet_vm.spawn.tail) || | ||||||
|              janet_vm.tq_count || |              janet_vm.tq_count || | ||||||
|              janet_vm.listener_count); |              janet_atomic_load(&janet_vm.listener_count)); | ||||||
| } | } | ||||||
|  |  | ||||||
| JanetFiber *janet_loop1(void) { | JanetFiber *janet_loop1(void) { | ||||||
| @@ -1346,7 +1346,7 @@ JanetFiber *janet_loop1(void) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* Poll for events */ |     /* 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; |         JanetTimeout to; | ||||||
|         memset(&to, 0, sizeof(to)); |         memset(&to, 0, sizeof(to)); | ||||||
|         int has_timeout; |         int has_timeout; | ||||||
| @@ -1365,7 +1365,7 @@ JanetFiber *janet_loop1(void) { | |||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|         /* Run polling implementation only if pending timeouts or pending events */ |         /* 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); |             janet_loop1_impl(has_timeout, to.when); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -647,6 +647,7 @@ typedef int32_t JanetAtomicInt; | |||||||
| #endif | #endif | ||||||
| JANET_API JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x); | JANET_API JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x); | ||||||
| JANET_API JanetAtomicInt janet_atomic_dec(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 | /* 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 |  * nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose