Skip to content

Commit

Permalink
Changed the way Mutex are check for lock on Signal handling (should h…
Browse files Browse the repository at this point in the history
…elp with freeze)
  • Loading branch information
ptitSeb committed May 21, 2021
1 parent ca95cdc commit b588709
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/box86context.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ int unlockMutex()
int ret = unlockCustommemMutex();
int i;
#define GO(A, B) \
i = checkMutex(&A); \
i = checkUnlockMutex(&A); \
if(i) { \
pthread_mutex_unlock(&A); \
ret|=(1<<B); \
}

Expand Down
3 changes: 1 addition & 2 deletions src/custommem.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,8 @@ int unlockCustommemMutex()
int ret = 0;
int i = 0;
#define GO(A, B) \
i = checkMutex(&A); \
i = checkUnlockMutex(&A); \
if(i) { \
pthread_mutex_unlock(&A); \
ret|=(1<<B); \
}
GO(mutex_blocks, 0)
Expand Down
4 changes: 2 additions & 2 deletions src/include/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void fini_pthread_helper(box86context_t* context);
// prepare an "emuthread structure" in pet and return address of function pointer for a "thread creation routine"
void* my_prepare_thread(x86emu_t *emu, void* f, void* arg, int ssize, void** pet);

//check if a mutex is locked by current thread (works only for PTHREAD_MUTEX_ERRORCHECK typed mutex)
int checkMutex(void* m);
//check and unlock if a mutex is locked by current thread (works only for PTHREAD_MUTEX_ERRORCHECK typed mutex)
int checkUnlockMutex(void* m);

#endif //_THREADS_H_
9 changes: 3 additions & 6 deletions src/libtools/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,15 +843,12 @@ void fini_pthread_helper(box86context_t* context)
}
}

int checkMutex(void* m)
int checkUnlockMutex(void* m)
{
pthread_mutex_t* mutex = (pthread_mutex_t*)m;
int ret = pthread_mutex_trylock(mutex);
int ret = pthread_mutex_unlock(mutex);
if(ret==0) {
pthread_mutex_unlock(mutex);
return 0;
}
if(ret==EDEADLK)
return 1;
}
return 0;
}

0 comments on commit b588709

Please sign in to comment.