Skip to content

Commit e7ca867

Browse files
committed
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. Manfred Koizar
1 parent e2ac58c commit e7ca867

File tree

8 files changed

+153
-181
lines changed

8 files changed

+153
-181
lines changed

src/backend/storage/ipc/ipci.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.58 2003/11/29 19:51:56 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.59 2003/12/01 21:59:25 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -111,8 +111,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
111111
* Set up lock manager
112112
*/
113113
InitLocks();
114-
if (InitLockTable(maxBackends) == INVALID_TABLEID)
115-
elog(FATAL, "could not create the lock table");
114+
InitLockTable(maxBackends);
116115

117116
/*
118117
* Set up process table

src/backend/storage/lmgr/deadlock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.26 2003/11/29 19:51:56 pgsql Exp $
15+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.27 2003/12/01 21:59:25 momjian Exp $
1616
*
1717
* Interface:
1818
*
@@ -428,7 +428,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
428428
LOCK *lock;
429429
PROCLOCK *proclock;
430430
SHM_QUEUE *lockHolders;
431-
LOCKMETHODTABLE *lockMethodTable;
431+
LockMethod lockMethodTable;
432432
PROC_QUEUE *waitQueue;
433433
int queue_size;
434434
int conflictMask;

src/backend/storage/lmgr/lmgr.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.61 2003/11/29 19:51:56 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.62 2003/12/01 21:59:25 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -65,38 +65,35 @@ static LOCKMASK LockConflicts[] = {
6565

6666
};
6767

68-
LOCKMETHOD LockTableId = (LOCKMETHOD) NULL;
69-
LOCKMETHOD LongTermTableId = (LOCKMETHOD) NULL;
68+
static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD;
7069

7170
/*
7271
* Create the lock table described by LockConflicts
7372
*/
74-
LOCKMETHOD
73+
void
7574
InitLockTable(int maxBackends)
7675
{
77-
int lockmethod;
76+
LOCKMETHODID LongTermTableId;
7877

7978
/* number of lock modes is lengthof()-1 because of dummy zero */
80-
lockmethod = LockMethodTableInit("LockTable",
81-
LockConflicts,
82-
lengthof(LockConflicts) - 1,
83-
maxBackends);
84-
LockTableId = lockmethod;
85-
86-
if (!(LockTableId))
79+
LockTableId = LockMethodTableInit("LockTable",
80+
LockConflicts,
81+
lengthof(LockConflicts) - 1,
82+
maxBackends);
83+
if (!LockMethodIsValid(LockTableId))
8784
elog(ERROR, "could not initialize lock table");
85+
Assert(LockTableId == DEFAULT_LOCKMETHOD);
8886

8987
#ifdef USER_LOCKS
9088

9189
/*
9290
* Allocate another tableId for long-term locks
9391
*/
9492
LongTermTableId = LockMethodTableRename(LockTableId);
95-
if (!(LongTermTableId))
93+
if (!LockMethodIsValid(LongTermTableId))
9694
elog(ERROR, "could not rename long-term lock table");
95+
Assert(LongTermTableId == USER_LOCKMETHOD);
9796
#endif
98-
99-
return LockTableId;
10097
}
10198

10299
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy