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];
6464bool Trace_lwlocks = false;
6565
6666inline 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{
6969if (Trace_lwlocks )
7070elog (DEBUG ,"%s(%d): excl %d shared %d head %p" ,
7171where , (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+
268279for (;;)
269280{
270281/* "false" means cannot accept cancel/die interrupt here. */
@@ -274,6 +285,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
274285extraWaits ++ ;
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 */
354367RESUME_INTERRUPTS ();
368+ LOG_LWDEBUG ("LWLockConditionalAcquire" ,lockid ,"failed" );
355369}
356370else
357371{
@@ -448,6 +462,7 @@ LWLockRelease(LWLockId lockid)
448462 */
449463while (head != NULL )
450464{
465+ LOG_LWDEBUG ("LWLockRelease" ,lockid ,"release waiter" );
451466proc = head ;
452467head = proc -> lwWaitLink ;
453468proc -> lwWaitLink = NULL ;