Skip to content

Commit b5c5c3f

Browse files
committed
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
1 parent 492bd64 commit b5c5c3f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/include/zorder.h

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ typedef struct _ZORDERINFO {
147147
# else
148148
pthread_mutex_t rwlock;
149149
# endif
150+
pthread_t wrlock_owner;
150151
#elif defined(_MGRM_PROCESSES)
151152
int zi_semid;
152153
int zi_semnum;

src/kernel/desktop.c

+10
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,30 @@ static void reset_window (PMAINWIN pWin, RECT* rcWin)
602602
static inline void lock_zi_for_change (const ZORDERINFO* zi)
603603
{
604604
pthread_rwlock_wrlock(&((ZORDERINFO*)zi)->rwlock);
605+
((ZORDERINFO*)zi)->wrlock_owner = pthread_self();
605606
}
606607

607608
static inline void unlock_zi_for_change (const ZORDERINFO* zi)
608609
{
609610
pthread_rwlock_unlock(&((ZORDERINFO*)zi)->rwlock);
611+
((ZORDERINFO*)zi)->wrlock_owner = 0;
610612
}
611613

612614
static inline void lock_zi_for_read (const ZORDERINFO* zi)
613615
{
616+
if (zi->wrlock_owner == pthread_self()) {
617+
return;
618+
}
619+
614620
pthread_rwlock_rdlock(&((ZORDERINFO*)zi)->rwlock);
615621
}
616622

617623
static inline void unlock_zi_for_read (const ZORDERINFO* zi)
618624
{
625+
if (zi->wrlock_owner == pthread_self()) {
626+
return;
627+
}
628+
619629
pthread_rwlock_unlock(&((ZORDERINFO*)zi)->rwlock);
620630
}
621631
#else /* __NOUNIX__ */

0 commit comments

Comments
 (0)