mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-02-06 10:21:57 +08:00
fix a deadlock bug (#87): use wrlock_owner to save the current thread holding the wrlock, skip rdlock if the wrlock owner is the current thread
This commit is contained in:
@@ -147,6 +147,7 @@ typedef struct _ZORDERINFO {
|
||||
# else
|
||||
pthread_mutex_t rwlock;
|
||||
# endif
|
||||
pthread_t wrlock_owner;
|
||||
#elif defined(_MGRM_PROCESSES)
|
||||
int zi_semid;
|
||||
int zi_semnum;
|
||||
|
||||
@@ -602,20 +602,30 @@ static void reset_window (PMAINWIN pWin, RECT* rcWin)
|
||||
static inline void lock_zi_for_change (const ZORDERINFO* zi)
|
||||
{
|
||||
pthread_rwlock_wrlock(&((ZORDERINFO*)zi)->rwlock);
|
||||
((ZORDERINFO*)zi)->wrlock_owner = pthread_self();
|
||||
}
|
||||
|
||||
static inline void unlock_zi_for_change (const ZORDERINFO* zi)
|
||||
{
|
||||
pthread_rwlock_unlock(&((ZORDERINFO*)zi)->rwlock);
|
||||
((ZORDERINFO*)zi)->wrlock_owner = 0;
|
||||
}
|
||||
|
||||
static inline void lock_zi_for_read (const ZORDERINFO* zi)
|
||||
{
|
||||
if (zi->wrlock_owner == pthread_self()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_rwlock_rdlock(&((ZORDERINFO*)zi)->rwlock);
|
||||
}
|
||||
|
||||
static inline void unlock_zi_for_read (const ZORDERINFO* zi)
|
||||
{
|
||||
if (zi->wrlock_owner == pthread_self()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_rwlock_unlock(&((ZORDERINFO*)zi)->rwlock);
|
||||
}
|
||||
#else /* __NOUNIX__ */
|
||||
|
||||
Reference in New Issue
Block a user