aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/lmgr/lock.c')
-rw-r--r--src/backend/storage/lmgr/lock.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index f68c595c8a4..0400a507779 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -578,11 +578,17 @@ DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
}
/*
- * LockHeldByMe -- test whether lock 'locktag' is held with mode 'lockmode'
- * by the current transaction
+ * LockHeldByMe -- test whether lock 'locktag' is held by the current
+ * transaction
+ *
+ * Returns true if current transaction holds a lock on 'tag' of mode
+ * 'lockmode'. If 'orstronger' is true, a stronger lockmode is also OK.
+ * ("Stronger" is defined as "numerically higher", which is a bit
+ * semantically dubious but is OK for the purposes we use this for.)
*/
bool
-LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
+LockHeldByMe(const LOCKTAG *locktag,
+ LOCKMODE lockmode, bool orstronger)
{
LOCALLOCKTAG localtag;
LOCALLOCK *locallock;
@@ -598,7 +604,23 @@ LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
&localtag,
HASH_FIND, NULL);
- return (locallock && locallock->nLocks > 0);
+ if (locallock && locallock->nLocks > 0)
+ return true;
+
+ if (orstronger)
+ {
+ LOCKMODE slockmode;
+
+ for (slockmode = lockmode + 1;
+ slockmode <= MaxLockMode;
+ slockmode++)
+ {
+ if (LockHeldByMe(locktag, slockmode, false))
+ return true;
+ }
+ }
+
+ return false;
}
#ifdef USE_ASSERT_CHECKING