about summary refs log tree commit diff stats
path: root/src/include
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-02-12 16:38:12 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-02-12 16:38:12 +0100
commit96a7d1e7ec0fa1266304779389359804e6108795 (patch)
tree889bec6cc539ff6a6ea655b56d293c874480700e /src/include
parent2d2a65b616b1bb4250cfdc1d300f7bbc14685a3a (diff)
downloadbox64-96a7d1e7ec0fa1266304779389359804e6108795.tar.gz
box64-96a7d1e7ec0fa1266304779389359804e6108795.zip
[DYNAREC] Use custom mutex, improved Signal while FillBlocks64 and atomic handling
Diffstat (limited to 'src/include')
-rwxr-xr-xsrc/include/box64context.h28
-rwxr-xr-xsrc/include/threads.h2
2 files changed, 25 insertions, 5 deletions
diff --git a/src/include/box64context.h b/src/include/box64context.h
index 3d8e0061..c8360017 100755
--- a/src/include/box64context.h
+++ b/src/include/box64context.h
@@ -4,6 +4,9 @@
 #include <pthread.h>
 #include "pathcoll.h"
 #include "dictionnary.h"
+#ifdef DYNAREC
+#include "dynarec/native_lock.h"
+#endif
 
 typedef struct elfheader_s elfheader_t;
 typedef struct cleanup_s cleanup_t;
@@ -123,17 +126,21 @@ typedef struct box64context_s {
     kh_defaultversion_t *weakdefver;    // the weak default version for symbols (the XXX@@vvvv of symbols)
     vkprocaddess_t      vkprocaddress;
 
-    pthread_mutex_t     mutex_trace;
     #ifndef DYNAREC
     pthread_mutex_t     mutex_lock;     // dynarec build will use their own mecanism
+    pthread_mutex_t     mutex_trace;
+    pthread_mutex_t     mutex_tls;
+    pthread_mutex_t     mutex_thread;
+    pthread_mutex_t     mutex_bridge;
     #else
-    pthread_mutex_t     mutex_dyndump;
+    uint32_t            mutex_dyndump;
+    uint32_t            mutex_trace;
+    uint32_t            mutex_tls;
+    uint32_t            mutex_thread;
+    uint32_t            mutex_bridge;
     uintptr_t           max_db_size;    // the biggest (in x86_64 instructions bytes) built dynablock
     int                 trace_dynarec;
     #endif
-    pthread_mutex_t     mutex_tls;
-    pthread_mutex_t     mutex_thread;
-    pthread_mutex_t     mutex_bridge;
 
     library_t           *libclib;       // shortcut to libc library (if loaded, so probably yes)
     library_t           *sdl1mixerlib;
@@ -188,6 +195,17 @@ typedef struct box64context_s {
 
 } box64context_t;
 
+#ifndef DYNAREC
+#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
+int GetTID();
+#define mutex_lock(A)       {uint32_t tid = (uint32_t)GetTID(); while(native_lock_storeifnull_d(A, tid)) sched_yield();}
+#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);
diff --git a/src/include/threads.h b/src/include/threads.h
index 847d4ee6..d094dc0b 100755
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -20,7 +20,9 @@ void fini_pthread_helper(box64context_t* context);
 // prepare an "emuthread structure" in pet and return address of function pointer for a "thread creation routine"
 void* my_prepare_thread(x64emu_t *emu, void* f, void* arg, int ssize, void** pet);
 
+#ifndef DYNAREC
 //check and unlock if a mutex is locked by current thread (works only for PTHREAD_MUTEX_ERRORCHECK typed mutex)
 int checkUnlockMutex(void* m);
+#endif
 
 #endif //_THREADS_H_
\ No newline at end of file