about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-07-05 11:35:27 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-07-05 11:35:27 +0200
commitc3cd14f3c529d75de5130facc3542f4a0f56d7f9 (patch)
treed936a68ddb784f69511274c139848feba67bf9bc /src
parent2010f8dcce4349e1420755a94f9af2211e9574c8 (diff)
downloadbox64-c3cd14f3c529d75de5130facc3542f4a0f56d7f9.tar.gz
box64-c3cd14f3c529d75de5130facc3542f4a0f56d7f9.zip
Removed mutex per bridge and use a global one (remove chance of freeze on fork)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/box64context.c4
-rwxr-xr-xsrc/include/box64context.h1
-rwxr-xr-xsrc/tools/bridge.c11
3 files changed, 9 insertions, 7 deletions
diff --git a/src/box64context.c b/src/box64context.c
index c3b228e6..5dc64825 100755
--- a/src/box64context.c
+++ b/src/box64context.c
@@ -88,6 +88,7 @@ int unlockMutex()
     #endif
     GO(my_context->mutex_tls, 9)
     GO(my_context->mutex_thread, 10)
+    GO(my_context->mutex_bridge, 11)
     #undef GO
 
     return ret;
@@ -110,6 +111,7 @@ void relockMutex(int locks)
     #endif
     GO(my_context->mutex_tls, 9)
     GO(my_context->mutex_thread, 10)
+    GO(my_context->mutex_bridge, 11)
     #undef GO
 }
 
@@ -128,6 +130,7 @@ static void init_mutexes(box64context_t* context)
 #endif
     pthread_mutex_init(&context->mutex_tls, &attr);
     pthread_mutex_init(&context->mutex_thread, &attr);
+    pthread_mutex_init(&context->mutex_bridge, &attr);
 
     pthread_mutexattr_destroy(&attr);
 }
@@ -268,6 +271,7 @@ void FreeBox64Context(box64context_t** context)
 #endif
     pthread_mutex_destroy(&ctx->mutex_tls);
     pthread_mutex_destroy(&ctx->mutex_thread);
+    pthread_mutex_destroy(&ctx->mutex_bridge);
 
     free_neededlib(&ctx->neededlibs);
 
diff --git a/src/include/box64context.h b/src/include/box64context.h
index 4a53fed8..0f99d1fe 100755
--- a/src/include/box64context.h
+++ b/src/include/box64context.h
@@ -121,6 +121,7 @@ typedef struct box64context_s {
     #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           *sdl1lib;       // shortcut to SDL1 library (if loaded)
diff --git a/src/tools/bridge.c b/src/tools/bridge.c
index e05bb1a3..8dc67ce1 100755
--- a/src/tools/bridge.c
+++ b/src/tools/bridge.c
@@ -30,7 +30,6 @@ typedef struct brick_s {
 typedef struct bridge_s {
     brick_t         *head;
     brick_t         *last;      // to speed up
-    pthread_mutex_t mutex;
     kh_bridgemap_t  *bridgemap;
 } bridge_t;
 
@@ -48,7 +47,6 @@ bridge_t *NewBridge()
     bridge_t *b = (bridge_t*)calloc(1, sizeof(bridge_t));
     b->head = NewBrick();
     b->last = b->head;
-    pthread_mutex_init(&b->mutex, NULL);
     b->bridgemap = kh_init(bridgemap);
 
     return b;
@@ -69,7 +67,6 @@ void FreeBridge(bridge_t** bridge)
         b = n;
     }
     kh_destroy(bridgemap, (*bridge)->bridgemap);
-    pthread_mutex_destroy(&(*bridge)->mutex);
     free(*bridge);
     *bridge = NULL;
 }
@@ -86,7 +83,7 @@ uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char*
     int prot = 0;
     do {
         #endif
-        pthread_mutex_lock(&bridge->mutex);
+        pthread_mutex_lock(&my_context->mutex_bridge);
         b = bridge->last;
         if(b->sz == NBRICK) {
             b->next = NewBrick();
@@ -95,7 +92,7 @@ uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char*
         }
 	    sz = b->sz;
         #ifdef DYNAREC
-        pthread_mutex_unlock(&bridge->mutex);
+        pthread_mutex_unlock(&my_context->mutex_bridge);
         if(box64_dynarec) {
             prot=(getProtection((uintptr_t)b->b)&PROT_DYNAREC)?1:0;
             if(prot)
@@ -104,7 +101,7 @@ uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char*
                 addDBFromAddressRange((uintptr_t)&b->b[b->sz].CC, sizeof(onebridge_t));
         }
     } while(sz!=b->sz); // this while loop if someone took the slot when the bridge mutex was unlocked doing memory protection managment
-    pthread_mutex_lock(&bridge->mutex);
+    pthread_mutex_lock(&my_context->mutex_bridge);
     #endif
     b->sz++;
     b->b[sz].CC = 0xCC;
@@ -117,7 +114,7 @@ uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char*
     int ret;
     khint_t k = kh_put(bridgemap, bridge->bridgemap, (uintptr_t)fnc, &ret);
     kh_value(bridge->bridgemap, k) = (uintptr_t)&b->b[sz].CC;
-    pthread_mutex_unlock(&bridge->mutex);
+    pthread_mutex_unlock(&my_context->mutex_bridge);
     #ifdef DYNAREC
     if(box64_dynarec)
         protectDB((uintptr_t)b->b, NBRICK*sizeof(onebridge_t));