Skip to content

Commit 1981527

Browse files
committed
Improve LOCK_DEBUG logging code for LWLocks.
1 parent ce286ff commit 1981527

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/backend/storage/lmgr/lwlock.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.4 2001/12/10 21:13:50 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.5 2001/12/28 23:26:04 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -64,16 +64,25 @@ static LWLockId held_lwlocks[MAX_SIMUL_LWLOCKS];
6464
bool Trace_lwlocks = false;
6565

6666
inline static void
67-
PRINT_LWDEBUG(const char *where, LWLockId lockid, const LWLock *lock)
67+
PRINT_LWDEBUG(const char *where, LWLockId lockid, const volatile LWLock *lock)
6868
{
6969
if (Trace_lwlocks)
7070
elog(DEBUG, "%s(%d): excl %d shared %d head %p",
7171
where, (int) lockid,
7272
(int) lock->exclusive, lock->shared, lock->head);
7373
}
7474

75+
inline static void
76+
LOG_LWDEBUG(const char *where, LWLockId lockid, const char *msg)
77+
{
78+
if (Trace_lwlocks)
79+
elog(DEBUG, "%s(%d): %s",
80+
where, (int) lockid, msg);
81+
}
82+
7583
#else /* not LOCK_DEBUG */
7684
#define PRINT_LWDEBUG(a,b,c)
85+
#define LOG_LWDEBUG(a,b,c)
7786
#endif /* LOCK_DEBUG */
7887

7988

@@ -265,6 +274,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
265274
* received, so that the lock manager or signal manager will see
266275
* the received signal when it next waits.
267276
*/
277+
LOG_LWDEBUG("LWLockAcquire", lockid, "waiting");
278+
268279
for (;;)
269280
{
270281
/* "false" means cannot accept cancel/die interrupt here. */
@@ -274,6 +285,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
274285
extraWaits++;
275286
}
276287

288+
LOG_LWDEBUG("LWLockAcquire", lockid, "awakened");
289+
277290
/*
278291
* The awakener already updated the lock struct's state, so we
279292
* don't need to do anything more to it. Just need to fix the
@@ -352,6 +365,7 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
352365
{
353366
/* Failed to get lock, so release interrupt holdoff */
354367
RESUME_INTERRUPTS();
368+
LOG_LWDEBUG("LWLockConditionalAcquire", lockid, "failed");
355369
}
356370
else
357371
{
@@ -448,6 +462,7 @@ LWLockRelease(LWLockId lockid)
448462
*/
449463
while (head != NULL)
450464
{
465+
LOG_LWDEBUG("LWLockRelease", lockid, "release waiter");
451466
proc = head;
452467
head = proc->lwWaitLink;
453468
proc->lwWaitLink = NULL;

0 commit comments

Comments
 (0)