From 6ad164d522d19d41fb12243079e23cc01cefbdeb Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 29 Mar 2021 18:39:00 +0200 Subject: [DYNAREC] DynaMap is behind a strict mutex now --- src/custommem.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/custommem.c b/src/custommem.c index eeba5f97..956e67fd 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -427,6 +427,7 @@ uintptr_t AllocDynarecMap(dynablock_t* db, int size) return 0; if(size>MMAPSIZE-2*sizeof(blockmark_t)) { #ifndef USE_MMAP + pthread_mutex_lock(&mutex_mmap); void *p = NULL; if(posix_memalign(&p, box64_pagesize, size)) { dynarec_log(LOG_INFO, "Cannot create dynamic map of %d bytes\n", size); @@ -450,14 +451,11 @@ uintptr_t AllocDynarecMap(dynablock_t* db, int size) int ret; k = kh_put(dynablocks, blocks, (uintptr_t)p, &ret); kh_value(blocks, k) = db; + pthread_mutex_unlock(&mutex_mmap); return (uintptr_t)p; } - if(pthread_mutex_trylock(&mutex_mmap)) { - sched_yield(); // give it a chance - if(pthread_mutex_trylock(&mutex_mmap)) - return 0; // cannot lock, baillout - } + pthread_mutex_lock(&mutex_mmap); uintptr_t ret = FindFreeDynarecMap(db, size); if(!ret) @@ -473,6 +471,7 @@ void FreeDynarecMap(dynablock_t* db, uintptr_t addr, uint32_t size) if(!addr || !size) return; if(size>MMAPSIZE-2*sizeof(blockmark_t)) { + pthread_mutex_lock(&mutex_mmap); #ifndef USE_MMAP free((void*)addr); #else @@ -484,6 +483,7 @@ void FreeDynarecMap(dynablock_t* db, uintptr_t addr, uint32_t size) if(k!=kh_end(blocks)) kh_del(dynablocks, blocks, k); } + pthread_mutex_unlock(&mutex_mmap); return; } pthread_mutex_lock(&mutex_mmap); @@ -516,12 +516,21 @@ void addDBFromAddressRange(uintptr_t addr, uintptr_t size) int idx3 = (i>>32)&((1<>16)&((1<>48)&0xffff; - idx2 = (((uintptr_t)addr)>>32)&0xffff; - idx1 = (((uintptr_t)addr)>>16)&0xffff; - idx0 = (((uintptr_t)addr) )&0xffff; + idx3 = ((addr)>>48)&0xffff; + idx2 = ((addr)>>32)&0xffff; + idx1 = ((addr)>>16)&0xffff; + idx0 = ((addr) )&0xffff; if(box64_jmptbl3[idx3] == box64_jmptbldefault2) { uintptr_t*** tbl = (uintptr_t***)malloc((1<