From 5ea247b84c046af8894cbe27ff5596e738fd47a1 Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Wed, 9 Apr 2025 21:21:55 +0800 Subject: Made custommem OS-independent (#2517) --- src/include/box64context.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/include/box64context.h') diff --git a/src/include/box64context.h b/src/include/box64context.h index 718d95b3..97c410ad 100644 --- a/src/include/box64context.h +++ b/src/include/box64context.h @@ -240,6 +240,21 @@ typedef struct box64context_s { } box64context_t; +#ifndef USE_CUSTOM_MUTEX +#define mutex_lock(A) pthread_mutex_lock(A) +#define mutex_trylock(A) pthread_mutex_trylock(A) +#define mutex_unlock(A) pthread_mutex_unlock(A) +#else +#define mutex_lock(A) \ + do { \ + uint32_t tid = (uint32_t)GetTID(); \ + while (native_lock_storeifnull_d(A, tid)) \ + sched_yield(); \ + } while (0) +#define mutex_trylock(A) native_lock_storeifnull_d(A, (uint32_t)GetTID()) +#define mutex_unlock(A) native_lock_storeifref_d(A, 0, (uint32_t)GetTID()) +#endif + extern box64context_t *my_context; // global context box64context_t *NewBox64Context(int argc); -- cgit 1.4.1