1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-13 12:08:07 +00:00

Expose atomic refcounts to be easier to port.

This code was duplicate in a few places.
This commit is contained in:
Calvin Rose
2023-10-01 10:09:23 -05:00
parent 26aa622afc
commit 7cdd7cf6eb
6 changed files with 58 additions and 41 deletions

View File

@@ -633,6 +633,20 @@ struct JanetListenerState {
};
#endif
/* Janet uses atomic integers in several places for synchronization between threads and
* signals. Define them here */
#ifdef JANET_WINDOWS
typedef long JanetAtomicInt;
typedef long long JanetAtomicInt64;
#else
typedef int32_t JanetAtomicInt;
typedef int64_t JanetAtomicInt64;
#endif
JANET_API JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x);
JANET_API JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x);
JANET_API JanetAtomicInt64 janet_atomic64_inc(JanetAtomicInt64 volatile *x);
JANET_API JanetAtomicInt64 janet_atomic64_dec(JanetAtomicInt64 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
* application must interact through exposed interface. */
@@ -896,7 +910,7 @@ struct JanetGCObject {
int32_t flags;
union {
JanetGCObject *next;
int32_t refcount; /* For threaded abstract types */
volatile JanetAtomicInt refcount; /* For threaded abstract types */
} data;
};