Mark ItemPointer arguments as const in tuple/table lock functions

The functions LockTuple, ConditionalLockTuple, UnlockTuple, and
XactLockTableWait take an ItemPointer argument that they do not
modify, so the argument can be const-qualified to better convey intent
and allow the compiler to enforce immutability.

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2m9e4rECHBwpRE4%2BGCH%2BpbYZXLh2f4rB1Du5hDfKug%2BOg%40mail.gmail.com
master
Peter Eisentraut 2 weeks ago
parent 710e6c4301
commit 991295f387
  1. 10
      src/backend/storage/lmgr/lmgr.c
  2. 8
      src/include/storage/lmgr.h

@ -55,7 +55,7 @@ typedef struct XactLockTableWaitInfo
{ {
XLTW_Oper oper; XLTW_Oper oper;
Relation rel; Relation rel;
ItemPointer ctid; const ItemPointerData *ctid;
} XactLockTableWaitInfo; } XactLockTableWaitInfo;
static void XactLockTableWaitErrorCb(void *arg); static void XactLockTableWaitErrorCb(void *arg);
@ -559,7 +559,7 @@ UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
* tuple. See heap_lock_tuple before using this! * tuple. See heap_lock_tuple before using this!
*/ */
void void
LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode) LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
@ -579,7 +579,7 @@ LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
* Returns true iff the lock was acquired. * Returns true iff the lock was acquired.
*/ */
bool bool
ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode, ConditionalLockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode,
bool logLockFailure) bool logLockFailure)
{ {
LOCKTAG tag; LOCKTAG tag;
@ -598,7 +598,7 @@ ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode,
* UnlockTuple * UnlockTuple
*/ */
void void
UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode) UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
@ -660,7 +660,7 @@ XactLockTableDelete(TransactionId xid)
* and if so wait for its parent. * and if so wait for its parent.
*/ */
void void
XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XactLockTableWait(TransactionId xid, Relation rel, const ItemPointerData *ctid,
XLTW_Oper oper) XLTW_Oper oper)
{ {
LOCKTAG tag; LOCKTAG tag;

@ -71,16 +71,16 @@ extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE l
extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
/* Lock a tuple (see heap_lock_tuple before assuming you understand this) */ /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); extern void LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode);
extern bool ConditionalLockTuple(Relation relation, ItemPointer tid, extern bool ConditionalLockTuple(Relation relation, const ItemPointerData *tid,
LOCKMODE lockmode, bool logLockFailure); LOCKMODE lockmode, bool logLockFailure);
extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); extern void UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode);
/* Lock an XID (used to wait for a transaction to finish) */ /* Lock an XID (used to wait for a transaction to finish) */
extern void XactLockTableInsert(TransactionId xid); extern void XactLockTableInsert(TransactionId xid);
extern void XactLockTableDelete(TransactionId xid); extern void XactLockTableDelete(TransactionId xid);
extern void XactLockTableWait(TransactionId xid, Relation rel, extern void XactLockTableWait(TransactionId xid, Relation rel,
ItemPointer ctid, XLTW_Oper oper); const ItemPointerData *ctid, XLTW_Oper oper);
extern bool ConditionalXactLockTableWait(TransactionId xid, extern bool ConditionalXactLockTableWait(TransactionId xid,
bool logLockFailure); bool logLockFailure);

Loading…
Cancel
Save