Skip to content

Commit 0464f25

Browse files
committed
Set MyProc->heldLocks in ProcSleep
Previously, ProcSleep()'s caller was responsible for setting MyProc->heldLocks, and we had comments to remind about that. But it seems simpler to make ProcSleep() itself responsible for it. ProcSleep() already set the other info about the lock its waiting for (waitLock, waitProcLock and waitLockMode), so it is natural for it to set heldLocks too. Reviewed-by: Maxim Orlov Discussion: https://www.postgresql.org/message-id/7c2090cd-a72a-4e34-afaa-6dd2ef31440e@iki.fi
1 parent 62620b6 commit 0464f25

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/backend/storage/lmgr/lock.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,11 +1095,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
10951095
}
10961096
else
10971097
{
1098-
/*
1099-
* Set bitmask of locks this process already holds on this object.
1100-
*/
1101-
MyProc->heldLocks = proclock->holdMask;
1102-
11031098
/*
11041099
* Sleep till someone wakes me up. We do this even in the dontWait
11051100
* case, because while trying to go to sleep, we may discover that we
@@ -1856,9 +1851,6 @@ MarkLockClear(LOCALLOCK *locallock)
18561851
/*
18571852
* WaitOnLock -- wait to acquire a lock
18581853
*
1859-
* Caller must have set MyProc->heldLocks to reflect locks already held
1860-
* on the lockable object by this process.
1861-
*
18621854
* The appropriate partition lock must be held at entry, and will still be
18631855
* held at exit.
18641856
*/

src/backend/storage/lmgr/proc.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,9 +1080,6 @@ AuxiliaryPidGetProc(int pid)
10801080
/*
10811081
* ProcSleep -- put a process to sleep on the specified lock
10821082
*
1083-
* Caller must have set MyProc->heldLocks to reflect locks already held
1084-
* on the lockable object by this process (under all XIDs).
1085-
*
10861083
* It's not actually guaranteed that we need to wait when this function is
10871084
* called, because it could be that when we try to find a position at which
10881085
* to insert ourself into the wait queue, we discover that we must be inserted
@@ -1112,7 +1109,8 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
11121109
LWLock *partitionLock = LockHashPartitionLock(hashcode);
11131110
dclist_head *waitQueue = &lock->waitProcs;
11141111
PGPROC *insert_before = NULL;
1115-
LOCKMASK myHeldLocks = MyProc->heldLocks;
1112+
LOCKMASK myProcHeldLocks;
1113+
LOCKMASK myHeldLocks;
11161114
TimestampTz standbyWaitStart = 0;
11171115
bool early_deadlock = false;
11181116
bool allow_autovacuum_cancel = true;
@@ -1121,6 +1119,8 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
11211119
PGPROC *leader = MyProc->lockGroupLeader;
11221120

11231121
/*
1122+
* Determine which locks we're already holding.
1123+
*
11241124
* If group locking is in use, locks held by members of my locking group
11251125
* need to be included in myHeldLocks. This is not required for relation
11261126
* extension lock which conflict among group members. However, including
@@ -1130,6 +1130,8 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
11301130
* that kind of locks, but there doesn't appear to be a clear advantage of
11311131
* the same.
11321132
*/
1133+
myProcHeldLocks = proclock->holdMask;
1134+
myHeldLocks = myProcHeldLocks;
11331135
if (leader != NULL)
11341136
{
11351137
dlist_iter iter;
@@ -1234,6 +1236,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
12341236
lock->waitMask |= LOCKBIT_ON(lockmode);
12351237

12361238
/* Set up wait information in PGPROC object, too */
1239+
MyProc->heldLocks = myProcHeldLocks;
12371240
MyProc->waitLock = lock;
12381241
MyProc->waitProcLock = proclock;
12391242
MyProc->waitLockMode = lockmode;

0 commit comments

Comments
 (0)