diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/custommem.c | 10 | ||||
| -rwxr-xr-x | src/libtools/threads.c | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/custommem.c b/src/custommem.c index 0358543d..80453230 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -882,6 +882,15 @@ void* findBlockNearHint(void* hint, size_t size) } #undef LOWEST +static void atfork_child_custommem(void) +{ + // unlock mutex if it was lock before the fork + pthread_mutex_unlock(&mutex_blocks); + pthread_mutex_unlock(&mutex_prot); +#ifdef DYNAREC + pthread_mutex_unlock(&mutex_mmap); +#endif +} void init_custommem_helper(box64context_t* ctx) { @@ -904,6 +913,7 @@ void init_custommem_helper(box64context_t* ctx) #error Unsupported architecture! #endif #endif + pthread_atfork(NULL, NULL, atfork_child_custommem); } void fini_custommem_helper(box64context_t *ctx) diff --git a/src/libtools/threads.c b/src/libtools/threads.c index ed37ca2c..07fd5d75 100755 --- a/src/libtools/threads.c +++ b/src/libtools/threads.c @@ -803,6 +803,21 @@ emu_jmpbuf_t* GetJmpBuf() return ejb; } +static void atfork_child(void) +{ + //unlock all potential mutex, this is a new fork! + pthread_mutex_unlock(&my_context->mutex_once); + pthread_mutex_unlock(&my_context->mutex_once2); + pthread_mutex_unlock(&my_context->mutex_trace); + #ifndef DYNAREC + pthread_mutex_unlock(&my_context->mutex_lock); + #else + pthread_mutex_unlock(&my_context->mutex_dyndump); + #endif + pthread_mutex_unlock(&my_context->mutex_tls); + pthread_mutex_unlock(&my_context->mutex_thread); +} + void init_pthread_helper() { InitCancelThread(); @@ -815,6 +830,7 @@ void init_pthread_helper() unaligned_mutex = kh_init(mutex); #endif #endif + pthread_atfork(NULL, NULL, atfork_child); } void fini_pthread_helper(box64context_t* context) |