Re: [PATCHES] Minor lmgr code cleanup

2003-12-01 Thread Bruce Momjian

Patch applied.  Thanks.  That lock manager code really needed the cleanup.

---


Manfred Koizar wrote:
 On Mon, 8 Sep 2003 13:02:11 -0400 (EDT), Bruce Momjian
 [EMAIL PROTECTED] wrote:
 
 Manfred, can I get a description for this patch?  Thanks.
 
 Try to reduce confusion about what is a lock method identifier, a lock
 method control structure, or a table of control structures.
 
 . Use type LOCKMASK where an int is not a counter.
 
 . Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.
 
 . Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
   LOCKMETHOD is not a pointer.
 
 . Define and use macro LockMethodIsValid.
 
 . Rename LOCKMETHOD to LOCKMETHODID.
 
 . Remove global variable LongTermTableId in lmgr.c, because it is
   never used.
 
 . Make LockTableId static in lmgr.c, because it is used nowhere else.
   Why not remove it and use DEFAULT_LOCKMETHOD?
 
 . Rename the lock method control structure from LOCKMETHODTABLE to
   LockMethodData.  Introduce a pointer type named LockMethod.
 
 . Remove elog(FATAL) after InitLockTable() call in
   CreateSharedMemoryAndSemaphores(), because if something goes wrong,
   there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
   help, an elog(ERROR) in InitLockTable() is promoted to FATAL.
 
 . Make InitLockTable() void, because its only caller does not use its
   return value any more.
 
 . Rename variables in lock.c to avoid statements like
   LockMethodTable[NumLockMethods] = lockMethodTable;
   lockMethodTable = LockMethodTable[lockmethod];
 
 . Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.
 
 . Remove static variables BITS_OFF and BITS_ON from lock.c, because
   I agree to this doubt:
  * XXX is a fetch from a static array really faster than a shift?
 
 . Define and use macros LOCKBIT_ON/OFF.
 
 ==
  All 93 tests passed.
 ==
 
 Servus
  Manfred
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [PATCHES] Minor lmgr code cleanup

2003-09-09 Thread Manfred Koizar
On Mon, 8 Sep 2003 13:02:11 -0400 (EDT), Bruce Momjian
[EMAIL PROTECTED] wrote:

Manfred, can I get a description for this patch?  Thanks.

Try to reduce confusion about what is a lock method identifier, a lock
method control structure, or a table of control structures.

. Use type LOCKMASK where an int is not a counter.

. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.

. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
  LOCKMETHOD is not a pointer.

. Define and use macro LockMethodIsValid.

. Rename LOCKMETHOD to LOCKMETHODID.

. Remove global variable LongTermTableId in lmgr.c, because it is
  never used.

. Make LockTableId static in lmgr.c, because it is used nowhere else.
  Why not remove it and use DEFAULT_LOCKMETHOD?

. Rename the lock method control structure from LOCKMETHODTABLE to
  LockMethodData.  Introduce a pointer type named LockMethod.

. Remove elog(FATAL) after InitLockTable() call in
  CreateSharedMemoryAndSemaphores(), because if something goes wrong,
  there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
  help, an elog(ERROR) in InitLockTable() is promoted to FATAL.

. Make InitLockTable() void, because its only caller does not use its
  return value any more.

. Rename variables in lock.c to avoid statements like
LockMethodTable[NumLockMethods] = lockMethodTable;
lockMethodTable = LockMethodTable[lockmethod];

. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.

. Remove static variables BITS_OFF and BITS_ON from lock.c, because
  I agree to this doubt:
 * XXX is a fetch from a static array really faster than a shift?

. Define and use macros LOCKBIT_ON/OFF.

==
 All 93 tests passed.
==

Servus
 Manfred

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] Minor lmgr code cleanup

2003-09-09 Thread Bruce Momjian

This has been saved for the 7.5 release:

http:/momjian.postgresql.org/cgi-bin/pgpatches2

---

Manfred Koizar wrote:
 On Mon, 8 Sep 2003 13:02:11 -0400 (EDT), Bruce Momjian
 [EMAIL PROTECTED] wrote:
 
 Manfred, can I get a description for this patch?  Thanks.
 
 Try to reduce confusion about what is a lock method identifier, a lock
 method control structure, or a table of control structures.
 
 . Use type LOCKMASK where an int is not a counter.
 
 . Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.
 
 . Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
   LOCKMETHOD is not a pointer.
 
 . Define and use macro LockMethodIsValid.
 
 . Rename LOCKMETHOD to LOCKMETHODID.
 
 . Remove global variable LongTermTableId in lmgr.c, because it is
   never used.
 
 . Make LockTableId static in lmgr.c, because it is used nowhere else.
   Why not remove it and use DEFAULT_LOCKMETHOD?
 
 . Rename the lock method control structure from LOCKMETHODTABLE to
   LockMethodData.  Introduce a pointer type named LockMethod.
 
 . Remove elog(FATAL) after InitLockTable() call in
   CreateSharedMemoryAndSemaphores(), because if something goes wrong,
   there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
   help, an elog(ERROR) in InitLockTable() is promoted to FATAL.
 
 . Make InitLockTable() void, because its only caller does not use its
   return value any more.
 
 . Rename variables in lock.c to avoid statements like
   LockMethodTable[NumLockMethods] = lockMethodTable;
   lockMethodTable = LockMethodTable[lockmethod];
 
 . Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.
 
 . Remove static variables BITS_OFF and BITS_ON from lock.c, because
   I agree to this doubt:
  * XXX is a fetch from a static array really faster than a shift?
 
 . Define and use macros LOCKBIT_ON/OFF.
 
 ==
  All 93 tests passed.
 ==
 
 Servus
  Manfred
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] Minor lmgr code cleanup

2003-09-08 Thread Manfred Koizar
On Mon, 8 Sep 2003 00:51:45 -0400 (EDT), Bruce Momjian
[EMAIL PROTECTED] wrote:

This has been saved for the 7.5 release:

   http:/momjian.postgresql.org/cgi-bin/pgpatches2

Here is the combined patch.  Prior patches in this thread are hereby
obsolete.

Servus
 Manfred
diff -ruN ../base/src/backend/storage/ipc/ipci.c src/backend/storage/ipc/ipci.c
--- ../base/src/backend/storage/ipc/ipci.c  2003-08-04 04:40:03.0 +0200
+++ src/backend/storage/ipc/ipci.c  2003-09-06 16:53:54.0 +0200
@@ -111,8 +111,7 @@
 * Set up lock manager
 */
InitLocks();
-   if (InitLockTable(maxBackends) == INVALID_TABLEID)
-   elog(FATAL, could not create the lock table);
+   InitLockTable(maxBackends);
 
/*
 * Set up process table
diff -ruN ../base/src/backend/storage/lmgr/deadlock.c 
src/backend/storage/lmgr/deadlock.c
--- ../base/src/backend/storage/lmgr/deadlock.c 2003-08-08 23:42:00.0 +0200
+++ src/backend/storage/lmgr/deadlock.c 2003-09-06 22:25:46.0 +0200
@@ -428,7 +428,7 @@
LOCK   *lock;
PROCLOCK   *proclock;
SHM_QUEUE  *lockHolders;
-   LOCKMETHODTABLE *lockMethodTable;
+   LockMethod  lockMethodTable;
PROC_QUEUE *waitQueue;
int queue_size;
int conflictMask;
diff -ruN ../base/src/backend/storage/lmgr/lmgr.c src/backend/storage/lmgr/lmgr.c
--- ../base/src/backend/storage/lmgr/lmgr.c 2003-08-18 00:41:12.0 +0200
+++ src/backend/storage/lmgr/lmgr.c 2003-09-06 18:10:48.0 +0200
@@ -65,26 +65,24 @@
 
 };
 
-LOCKMETHOD LockTableId = (LOCKMETHOD) NULL;
-LOCKMETHOD LongTermTableId = (LOCKMETHOD) NULL;
+static LOCKMETHODIDLockTableId = INVALID_LOCKMETHOD;
 
 /*
  * Create the lock table described by LockConflicts
  */
-LOCKMETHOD
+void
 InitLockTable(int maxBackends)
 {
-   int lockmethod;
+   LOCKMETHODIDLongTermTableId;
 
/* number of lock modes is lengthof()-1 because of dummy zero */
-   lockmethod = LockMethodTableInit(LockTable,
-LockConflicts,
-
lengthof(LockConflicts) - 1,
-maxBackends);
-   LockTableId = lockmethod;
-
-   if (!(LockTableId))
+   LockTableId = LockMethodTableInit(LockTable,
+ 
LockConflicts,
+ 
lengthof(LockConflicts) - 1,
+ maxBackends);
+   if (!LockMethodIsValid(LockTableId))
elog(ERROR, could not initialize lock table);
+   Assert(LockTableId == DEFAULT_LOCKMETHOD);
 
 #ifdef USER_LOCKS
 
@@ -92,11 +90,10 @@
 * Allocate another tableId for long-term locks
 */
LongTermTableId = LockMethodTableRename(LockTableId);
-   if (!(LongTermTableId))
+   if (!LockMethodIsValid(LongTermTableId))
elog(ERROR, could not rename long-term lock table);
+   Assert(LongTermTableId == USER_LOCKMETHOD);
 #endif
-
-   return LockTableId;
 }
 
 /*
diff -ruN ../base/src/backend/storage/lmgr/lock.c src/backend/storage/lmgr/lock.c
--- ../base/src/backend/storage/lmgr/lock.c 2003-08-18 00:41:12.0 +0200
+++ src/backend/storage/lmgr/lock.c 2003-09-07 07:53:16.0 +0200
@@ -46,7 +46,7 @@
 #define NLOCKENTS(maxBackends) (max_locks_per_xact * (maxBackends))
 
 
-static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
+static int WaitOnLock(LOCKMETHODID lockmethodid, LOCKMODE lockmode,
   LOCK *lock, PROCLOCK *proclock);
 static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc,
 int *myHolding);
@@ -111,7 +111,7 @@
 req(%d,%d,%d,%d,%d,%d,%d)=%d 
 grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s),
 where, MAKE_OFFSET(lock),
-lock-tag.lockmethod, lock-tag.relId, lock-tag.dbId,
+lock-tag.lockmethodid, lock-tag.relId, lock-tag.dbId,
 lock-tag.objId.blkno, lock-grantMask,
 lock-requested[1], lock-requested[2], lock-requested[3],
 lock-requested[4], lock-requested[5], lock-requested[6],
@@ -150,19 +150,9 @@
 
 
 /*
- * These are to simplify/speed up some bit arithmetic.
- *
- * XXX is a fetch from a static array really faster than a shift?
- * Wouldn't bet on it...
+ * map from lock method id to the lock table structure
  */
-
-static LOCKMASK BITS_OFF[MAX_LOCKMODES];
-static LOCKMASK BITS_ON[MAX_LOCKMODES];
-
-/*
- * map from lockmethod to the lock table structure
- */

Re: [PATCHES] Minor lmgr code cleanup

2003-09-08 Thread Bruce Momjian

Manfred, can I get a description for this patch?  Thanks.

---

Manfred Koizar wrote:
 On Mon, 8 Sep 2003 00:51:45 -0400 (EDT), Bruce Momjian
 [EMAIL PROTECTED] wrote:
 
 This has been saved for the 7.5 release:
 
  http:/momjian.postgresql.org/cgi-bin/pgpatches2
 
 Here is the combined patch.  Prior patches in this thread are hereby
 obsolete.
 
 Servus
  Manfred

 diff -ruN ../base/src/backend/storage/ipc/ipci.c src/backend/storage/ipc/ipci.c
 --- ../base/src/backend/storage/ipc/ipci.c2003-08-04 04:40:03.0 +0200
 +++ src/backend/storage/ipc/ipci.c2003-09-06 16:53:54.0 +0200
 @@ -111,8 +111,7 @@
* Set up lock manager
*/
   InitLocks();
 - if (InitLockTable(maxBackends) == INVALID_TABLEID)
 - elog(FATAL, could not create the lock table);
 + InitLockTable(maxBackends);
  
   /*
* Set up process table
 diff -ruN ../base/src/backend/storage/lmgr/deadlock.c 
 src/backend/storage/lmgr/deadlock.c
 --- ../base/src/backend/storage/lmgr/deadlock.c   2003-08-08 23:42:00.0 
 +0200
 +++ src/backend/storage/lmgr/deadlock.c   2003-09-06 22:25:46.0 +0200
 @@ -428,7 +428,7 @@
   LOCK   *lock;
   PROCLOCK   *proclock;
   SHM_QUEUE  *lockHolders;
 - LOCKMETHODTABLE *lockMethodTable;
 + LockMethod  lockMethodTable;
   PROC_QUEUE *waitQueue;
   int queue_size;
   int conflictMask;
 diff -ruN ../base/src/backend/storage/lmgr/lmgr.c src/backend/storage/lmgr/lmgr.c
 --- ../base/src/backend/storage/lmgr/lmgr.c   2003-08-18 00:41:12.0 +0200
 +++ src/backend/storage/lmgr/lmgr.c   2003-09-06 18:10:48.0 +0200
 @@ -65,26 +65,24 @@
  
  };
  
 -LOCKMETHOD   LockTableId = (LOCKMETHOD) NULL;
 -LOCKMETHOD   LongTermTableId = (LOCKMETHOD) NULL;
 +static   LOCKMETHODIDLockTableId = INVALID_LOCKMETHOD;
  
  /*
   * Create the lock table described by LockConflicts
   */
 -LOCKMETHOD
 +void
  InitLockTable(int maxBackends)
  {
 - int lockmethod;
 + LOCKMETHODIDLongTermTableId;
  
   /* number of lock modes is lengthof()-1 because of dummy zero */
 - lockmethod = LockMethodTableInit(LockTable,
 -  LockConflicts,
 -  
 lengthof(LockConflicts) - 1,
 -  maxBackends);
 - LockTableId = lockmethod;
 -
 - if (!(LockTableId))
 + LockTableId = LockMethodTableInit(LockTable,
 +   
 LockConflicts,
 +   
 lengthof(LockConflicts) - 1,
 +   maxBackends);
 + if (!LockMethodIsValid(LockTableId))
   elog(ERROR, could not initialize lock table);
 + Assert(LockTableId == DEFAULT_LOCKMETHOD);
  
  #ifdef USER_LOCKS
  
 @@ -92,11 +90,10 @@
* Allocate another tableId for long-term locks
*/
   LongTermTableId = LockMethodTableRename(LockTableId);
 - if (!(LongTermTableId))
 + if (!LockMethodIsValid(LongTermTableId))
   elog(ERROR, could not rename long-term lock table);
 + Assert(LongTermTableId == USER_LOCKMETHOD);
  #endif
 -
 - return LockTableId;
  }
  
  /*
 diff -ruN ../base/src/backend/storage/lmgr/lock.c src/backend/storage/lmgr/lock.c
 --- ../base/src/backend/storage/lmgr/lock.c   2003-08-18 00:41:12.0 +0200
 +++ src/backend/storage/lmgr/lock.c   2003-09-07 07:53:16.0 +0200
 @@ -46,7 +46,7 @@
  #define NLOCKENTS(maxBackends)   (max_locks_per_xact * (maxBackends))
  
  
 -static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
 +static int WaitOnLock(LOCKMETHODID lockmethodid, LOCKMODE lockmode,
  LOCK *lock, PROCLOCK *proclock);
  static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc,
int *myHolding);
 @@ -111,7 +111,7 @@
req(%d,%d,%d,%d,%d,%d,%d)=%d 
grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s),
where, MAKE_OFFSET(lock),
 -  lock-tag.lockmethod, lock-tag.relId, lock-tag.dbId,
 +  lock-tag.lockmethodid, lock-tag.relId, lock-tag.dbId,
lock-tag.objId.blkno, lock-grantMask,
lock-requested[1], lock-requested[2], lock-requested[3],
lock-requested[4], lock-requested[5], lock-requested[6],
 @@ -150,19 +150,9 @@
  
  
  /*
 - * These are to simplify/speed up some bit arithmetic.
 - *
 - * XXX is a fetch from a static array really faster than a shift?
 - * Wouldn't bet on it...
 + * map from lock 

[PATCHES] Minor lmgr code cleanup

2003-09-07 Thread Manfred Koizar
Try to reduce confusion about what is a lock method identifier, a lock
method control structure, or a table of control structures.

. Use type LOCKMASK where an int is not a counter.

. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.

. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
  LOCKMETHOD is not a pointer.

. Define and use macro LockMethodIsValid.

. Rename LOCKMETHOD to LOCKMETHODID.

. Remove global variable LongTermTableId in lmgr.c, because it is
  never used.

. Make LockTableId static in lmgr.c, because it is used nowhere else.
  Why not remove it and use DEFAULT_LOCKMETHOD?

. Rename the lock method control structure from LOCKMETHODTABLE to
  LockMethodData.  Introduce a pointer type named LockMethod.

. Remove elog(FATAL) after InitLockTable() call in
  CreateSharedMemoryAndSemaphores(), because if something goes wrong,
  there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
  help, an elog(ERROR) in InitLockTable() is promoted to FATAL.

. Make InitLockTable() void, because its only caller does not use its
  return value any more.

. Rename variables in lock.c to avoid statements like
LockMethodTable[NumLockMethods] = lockMethodTable;
lockMethodTable = LockMethodTable[lockmethod];

. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.

. Remove static variables BITS_OFF and BITS_ON from lock.c, because
  I agree to this doubt:
 * XXX is a fetch from a static array really faster than a shift?

==
 All 93 tests passed.
==

Servus
 Manfred
diff -ruN ../base/src/backend/storage/ipc/ipci.c src/backend/storage/ipc/ipci.c
--- ../base/src/backend/storage/ipc/ipci.c  2003-08-04 04:40:03.0 +0200
+++ src/backend/storage/ipc/ipci.c  2003-09-06 16:53:54.0 +0200
@@ -111,8 +111,7 @@
 * Set up lock manager
 */
InitLocks();
-   if (InitLockTable(maxBackends) == INVALID_TABLEID)
-   elog(FATAL, could not create the lock table);
+   InitLockTable(maxBackends);
 
/*
 * Set up process table
diff -ruN ../base/src/backend/storage/lmgr/deadlock.c 
src/backend/storage/lmgr/deadlock.c
--- ../base/src/backend/storage/lmgr/deadlock.c 2003-08-08 23:42:00.0 +0200
+++ src/backend/storage/lmgr/deadlock.c 2003-09-06 22:25:46.0 +0200
@@ -428,7 +428,7 @@
LOCK   *lock;
PROCLOCK   *proclock;
SHM_QUEUE  *lockHolders;
-   LOCKMETHODTABLE *lockMethodTable;
+   LockMethod  lockMethodTable;
PROC_QUEUE *waitQueue;
int queue_size;
int conflictMask;
diff -ruN ../base/src/backend/storage/lmgr/lmgr.c src/backend/storage/lmgr/lmgr.c
--- ../base/src/backend/storage/lmgr/lmgr.c 2003-08-18 00:41:12.0 +0200
+++ src/backend/storage/lmgr/lmgr.c 2003-09-06 18:10:48.0 +0200
@@ -65,26 +65,24 @@
 
 };
 
-LOCKMETHOD LockTableId = (LOCKMETHOD) NULL;
-LOCKMETHOD LongTermTableId = (LOCKMETHOD) NULL;
+static LOCKMETHODIDLockTableId = INVALID_LOCKMETHOD;
 
 /*
  * Create the lock table described by LockConflicts
  */
-LOCKMETHOD
+void
 InitLockTable(int maxBackends)
 {
-   int lockmethod;
+   LOCKMETHODIDLongTermTableId;
 
/* number of lock modes is lengthof()-1 because of dummy zero */
-   lockmethod = LockMethodTableInit(LockTable,
-LockConflicts,
-
lengthof(LockConflicts) - 1,
-maxBackends);
-   LockTableId = lockmethod;
-
-   if (!(LockTableId))
+   LockTableId = LockMethodTableInit(LockTable,
+ 
LockConflicts,
+ 
lengthof(LockConflicts) - 1,
+ maxBackends);
+   if (!LockMethodIsValid(LockTableId))
elog(ERROR, could not initialize lock table);
+   Assert(LockTableId == DEFAULT_LOCKMETHOD);
 
 #ifdef USER_LOCKS
 
@@ -92,11 +90,10 @@
 * Allocate another tableId for long-term locks
 */
LongTermTableId = LockMethodTableRename(LockTableId);
-   if (!(LongTermTableId))
+   if (!LockMethodIsValid(LongTermTableId))
elog(ERROR, could not rename long-term lock table);
+   Assert(LongTermTableId == USER_LOCKMETHOD);
 #endif
-
-   return LockTableId;
 }
 
 /*
diff -ruN ../base/src/backend/storage/lmgr/lock.c src/backend/storage/lmgr/lock.c
--- ../base/src/backend/storage/lmgr/lock.c 2003-08-18 00:41:12.0 +0200
+++ src/backend/storage/lmgr/lock.c 2003-09-06 23:01:05.0 +0200
@@ -46,7 +46,7 @@
 #define NLOCKENTS(maxBackends) 

Re: [PATCHES] Minor lmgr code cleanup

2003-09-07 Thread Tom Lane
Manfred Koizar [EMAIL PROTECTED] writes:
 I'd put another pair of parens around that. [etc]

 Done.  Small patch attached, should be applied after the large patch.
 Big fat all-in-one patch available on request.

Looks good to me.  Bruce, please add to pending queue for 7.5?

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] Minor lmgr code cleanup

2003-09-07 Thread Bruce Momjian

This has been saved for the 7.5 release:

http:/momjian.postgresql.org/cgi-bin/pgpatches2

---

Manfred Koizar wrote:
 On Sun, 07 Sep 2003 10:19:07 -0400, Tom Lane [EMAIL PROTECTED]
 wrote:
  +#define BITS_OFF(i) ~(1  (i))
 
 I'd put another pair of parens around that.  Also, it might be worth
 moving into a header file.  There is at least one place in proc.c that
 manipulates lock masks using explicit shifts, because BITS_ON/BITS_OFF
 weren't visible outside lock.c.
 
 Done.  Small patch attached, should be applied after the large patch.
 Big fat all-in-one patch available on request.
 
 BTW, did you check that the code still compiles with LOCK_DEBUG enabled?
 
 No, I didn't and it didn't. :-(  Corrected.
 
 How about contrib/userlock?
 
 Unaffected by my changes, still works AFAICT.
 
 Servus
  Manfred

 diff -ruN ../base/src/backend/storage/lmgr/lock.c src/backend/storage/lmgr/lock.c
 --- ../base/src/backend/storage/lmgr/lock.c   2003-09-06 23:01:05.0 +0200
 +++ src/backend/storage/lmgr/lock.c   2003-09-07 07:53:16.0 +0200
 @@ -111,7 +111,7 @@
req(%d,%d,%d,%d,%d,%d,%d)=%d 
grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s),
where, MAKE_OFFSET(lock),
 -  lock-tag.lockmethod, lock-tag.relId, lock-tag.dbId,
 +  lock-tag.lockmethodid, lock-tag.relId, lock-tag.dbId,
lock-tag.objId.blkno, lock-grantMask,
lock-requested[1], lock-requested[2], lock-requested[3],
lock-requested[4], lock-requested[5], lock-requested[6],
 @@ -150,12 +150,6 @@
  
  
  /*
 - * These are to simplify some bit arithmetic.
 - */
 -#define BITS_ON(i) (1  (i))
 -#define BITS_OFF(i) ~(1  (i))
 -
 -/*
   * map from lock method id to the lock table structure
   */
  static LockMethod LockMethods[MAX_LOCK_METHODS];
 @@ -654,15 +648,12 @@
* Construct bitmask of locks this process holds on this object.
*/
   {
 - int heldLocks = 0;
 - int tmpMask;
 + LOCKMASKheldLocks = 0;
  
 - for (i = 1, tmpMask = 2;
 -  i = lockMethodTable-numLockModes;
 -  i++, tmpMask = 1)
 + for (i = 1; i = lockMethodTable-numLockModes; i++)
   {
   if (myHolding[i]  0)
 - heldLocks |= tmpMask;
 + heldLocks |= LOCKBIT_ON(i);
   }
   MyProc-heldLocks = heldLocks;
   }
 @@ -725,9 +716,8 @@
  int *myHolding)  /* myHolding[] array 
 or NULL */
  {
   int numLockModes = lockMethodTable-numLockModes;
 - int bitmask;
 - int i,
 - tmpMask;
 + LOCKMASKbitmask;
 + int i;
   int localHolding[MAX_LOCKMODES];
  
   /*
 @@ -760,11 +750,10 @@
  
   /* Compute mask of lock types held by other processes */
   bitmask = 0;
 - tmpMask = 2;
 - for (i = 1; i = numLockModes; i++, tmpMask = 1)
 + for (i = 1; i = numLockModes; i++)
   {
   if (lock-granted[i] != myHolding[i])
 - bitmask |= tmpMask;
 + bitmask |= LOCKBIT_ON(i);
   }
  
   /*
 @@ -830,9 +819,9 @@
  {
   lock-nGranted++;
   lock-granted[lockmode]++;
 - lock-grantMask |= BITS_ON(lockmode);
 + lock-grantMask |= LOCKBIT_ON(lockmode);
   if (lock-granted[lockmode] == lock-requested[lockmode])
 - lock-waitMask = BITS_OFF(lockmode);
 + lock-waitMask = LOCKBIT_OFF(lockmode);
   LOCK_PRINT(GrantLock, lock, lockmode);
   Assert((lock-nGranted  0)  (lock-granted[lockmode]  0));
   Assert(lock-nGranted = lock-nRequested);
 @@ -945,7 +934,7 @@
   waitLock-requested[lockmode]--;
   /* don't forget to clear waitMask bit if appropriate */
   if (waitLock-granted[lockmode] == waitLock-requested[lockmode])
 - waitLock-waitMask = BITS_OFF(lockmode);
 + waitLock-waitMask = LOCKBIT_OFF(lockmode);
  
   /* Clean up the proc's own state */
   proc-waitLock = NULL;
 @@ -1071,7 +1060,7 @@
   if (lock-granted[lockmode] == 0)
   {
   /* change the conflict mask.  No more of this lock type. */
 - lock-grantMask = BITS_OFF(lockmode);
 + lock-grantMask = LOCKBIT_OFF(lockmode);
   }
  
   LOCK_PRINT(LockRelease: updated, lock, lockmode);
 @@ -1237,7 +1226,7 @@
   lock-granted[i] -=