From e6b68955bd0b28ef7d49c9d9db7cbf42befc2f96 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 3 Oct 2006 03:48:23 +0000 Subject: [PATCH] DEVEL15-windows-track-lock-tid-20061002 Keep track of the tid of the holding thread for writers (cherry picked from commit b17a5d8192c08909ae57b540b25804ad9e1ae8a3) --- src/WINNT/client_osi/osibasel.c | 18 ++++++++++++++++-- src/WINNT/client_osi/osibasel.h | 1 + src/WINNT/client_osi/osistatl.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/WINNT/client_osi/osibasel.c b/src/WINNT/client_osi/osibasel.c index ca740544c..fff810df8 100644 --- a/src/WINNT/client_osi/osibasel.c +++ b/src/WINNT/client_osi/osibasel.c @@ -56,6 +56,8 @@ void lock_ObtainWrite(osi_rwlock_t *lockp) lockp->flags |= OSI_LOCKFLAG_EXCL; } + lockp->tid = thrd_Current(); + LeaveCriticalSection(csp); } @@ -85,7 +87,8 @@ void lock_ObtainRead(osi_rwlock_t *lockp) /* if we're here, all clear to set the lock */ lockp->readers++; } - LeaveCriticalSection(csp); + + LeaveCriticalSection(csp); } void lock_ReleaseRead(osi_rwlock_t *lockp) @@ -132,6 +135,8 @@ void lock_ReleaseWrite(osi_rwlock_t *lockp) osi_assertx(lockp->flags & OSI_LOCKFLAG_EXCL, "write lock not held"); + lockp->tid = 0; + lockp->flags &= ~OSI_LOCKFLAG_EXCL; if (!osi_TEmpty(&lockp->d.turn)) { osi_TSignalForMLs(&lockp->d.turn, 0, csp); @@ -163,6 +168,8 @@ void lock_ConvertWToR(osi_rwlock_t *lockp) lockp->flags &= ~OSI_LOCKFLAG_EXCL; lockp->readers++; + lockp->tid = 0; + if (!osi_TEmpty(&lockp->d.turn)) { osi_TSignalForMLs(&lockp->d.turn, /* still have readers */ 1, csp); } @@ -283,7 +290,10 @@ int lock_TryWrite(struct osi_rwlock *lockp) i = 1; } - LeaveCriticalSection(csp); + if (i) + lockp->tid = thrd_Current(); + + LeaveCriticalSection(csp); return i; } @@ -311,6 +321,9 @@ int lock_TryMutex(struct osi_mutex *lockp) { i = 1; } + if (i) + lockp->tid = thrd_Current(); + LeaveCriticalSection(csp); return i; @@ -452,6 +465,7 @@ void lock_InitializeRWLock(osi_rwlock_t *mp, char *namep) mp->flags = 0; mp->atomicIndex = osi_MUTEXHASH(mp); mp->readers = 0; + mp->tid = 0; osi_TInit(&mp->d.turn); return; } diff --git a/src/WINNT/client_osi/osibasel.h b/src/WINNT/client_osi/osibasel.h index f5482b472..633ee84c9 100644 --- a/src/WINNT/client_osi/osibasel.h +++ b/src/WINNT/client_osi/osibasel.h @@ -56,6 +56,7 @@ typedef struct osi_rwlock { char type; /* for all types; type 0 uses atomic count */ char flags; /* flags for base type */ unsigned short atomicIndex; /* index into hash table for low-level sync */ + DWORD tid; /* writer's tid */ unsigned short waiters; /* waiters */ unsigned short readers; /* readers */ union { diff --git a/src/WINNT/client_osi/osistatl.h b/src/WINNT/client_osi/osistatl.h index e2dd99f4c..3de16465c 100644 --- a/src/WINNT/client_osi/osistatl.h +++ b/src/WINNT/client_osi/osistatl.h @@ -59,6 +59,7 @@ typedef struct osi_mutexStat { osi_turnstile_t turn; /* the real turnstile */ unsigned long refCount; /* so we can iterate cleanly */ short states; + DWORD tid; /* track # of lock calls and blocks */ LARGE_INTEGER lockedTime; /* total time held */ @@ -81,6 +82,7 @@ typedef struct osi_rwlockStat { osi_turnstile_t turn; /* the real turnstile */ unsigned long refCount; /* so we can iterate cleanly */ short states; + DWORD tid; /* statistics */ LARGE_INTEGER writeLockedTime; /* total time held */ -- 2.39.5