77 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.79 2004/07/17 03:31:26 tgl Exp $
10+ * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.80 2004/08/26 17:22:28 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -26,10 +26,10 @@ typedef struct PROC_QUEUE
2626int size ;/* number of entries in list */
2727}PROC_QUEUE ;
2828
29- /* struct PGPROC is declared instorage/ proc.h, but must forward-reference it */
29+ /* struct PGPROC is declared in proc.h, but must forward-reference it */
3030typedef struct PGPROC PGPROC ;
3131
32-
32+ /* GUC variables */
3333extern int max_locks_per_xact ;
3434
3535#ifdef LOCK_DEBUG
@@ -41,6 +41,11 @@ extern bool Debug_deadlocks;
4141#endif /* LOCK_DEBUG */
4242
4343
44+ /*
45+ * LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit
46+ * mask indicating a set of held or requested lock types (the bit 1<<mode
47+ * corresponds to a particular lock mode).
48+ */
4449typedef int LOCKMASK ;
4550typedef int LOCKMODE ;
4651/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
@@ -49,6 +54,11 @@ typedef int LOCKMODE;
4954#define LOCKBIT_ON (lockmode ) (1 << (lockmode))
5055#define LOCKBIT_OFF (lockmode ) (~(1 << (lockmode)))
5156
57+ /*
58+ * There is normally only one lock method, the default one.
59+ * If user locks are enabled, an additional lock method is present.
60+ * Lock methods are identified by LOCKMETHODID.
61+ */
5262typedef uint16 LOCKMETHODID ;
5363/* MAX_LOCK_METHODS is the number of distinct lock control tables allowed */
5464#define MAX_LOCK_METHODS 3
@@ -60,18 +70,13 @@ typedef uint16 LOCKMETHODID;
6070#define LockMethodIsValid (lockmethodid ) ((lockmethodid) != INVALID_LOCKMETHOD)
6171
6272/*
63- * There is normally only one lock method, the default one.
64- * If user locks are enabled, an additional lock method is present.
65- *
66- * This is the control structure for a lock table.It
67- * lives in shared memory.This information is the same
68- * for all backends.
73+ * This is the control structure for a lock table. It lives in shared
74+ * memory. Currently, none of these fields change after startup. In addition
75+ * to the LockMethodData, a lock table has a "lockHash" table holding
76+ * per-locked-object lock information, and a "proclockHash" table holding
77+ * per-lock-holder/waiter lock information.
6978 *
70- * lockHash -- hash table holding per-locked-object lock information
71- *
72- * proclockHash -- hash table holding per-lock-waiter/holder lock information
73- *
74- * lockmethod -- the handle used by the lock table's clients to
79+ * lockmethodid -- the handle used by the lock table's clients to
7580 *refer to the type of lock table being used.
7681 *
7782 * numLockModes -- number of lock types (READ,WRITE,etc) that
@@ -81,8 +86,7 @@ typedef uint16 LOCKMETHODID;
8186 *type conflicts. conflictTab[i] is a mask with the j-th bit
8287 *turned on if lock types i and j conflict.
8388 *
84- * masterLock -- synchronizes access to the table
85- *
89+ * masterLock -- LWLock used to synchronize access to the table
8690 */
8791typedef struct LockMethodData
8892{
@@ -156,12 +160,13 @@ typedef struct LOCK
156160
157161/*
158162 * We may have several different transactions holding or awaiting locks
159- * on the same lockable object. We need to store some per-waiter/holder
160- * information for each such holder (or would-be holder).
163+ * on the same lockable object. We need to store some per-holder/waiter
164+ * information for each such holder (or would-be holder). This is kept in
165+ * a PROCLOCK struct.
161166 *
162167 * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the
163- * proclock hashtable.A PROCLOCKTAG value uniquely identifiesa lock
164- * holder/waiter.
168+ * proclock hashtable.A PROCLOCKTAG value uniquely identifiesthe combination
169+ *of a lockable object and a holder/waiter for that object .
165170 *
166171 * There are two possible kinds of proclock tags: a transaction (identified
167172 * both by the PGPROC of the backend running it, and the xact's own ID) and