aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2016-09-05 10:38:08 +0100
committerSimon Riggs <simon@2ndQuadrant.com>2016-09-05 10:38:08 +0100
commit016abf1fb8333de82a259af0cc7572a4b868023b (patch)
tree9b50dfce2a113b0563ddce042d1fa6582e7c4a56 /src
parentec03f4121cec6cf885bf40d9dfb53b8368251e99 (diff)
downloadpostgresql-016abf1fb8333de82a259af0cc7572a4b868023b.tar.gz
postgresql-016abf1fb8333de82a259af0cc7572a4b868023b.zip
Add debug check function LWLockHeldByMeInMode()
Tests whether my process holds a lock in given mode. Add initial usage in MarkBufferDirty(). Thomas Munro
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/buffer/bufmgr.c4
-rw-r--r--src/backend/storage/lmgr/lwlock.c23
-rw-r--r--src/include/storage/lwlock.h1
3 files changed, 23 insertions, 5 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 76ade3727cd..90804a3c530 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -1460,8 +1460,8 @@ MarkBufferDirty(Buffer buffer)
bufHdr = GetBufferDescriptor(buffer - 1);
Assert(BufferIsPinned(buffer));
- /* unfortunately we can't check if the lock is held exclusively */
- Assert(LWLockHeldByMe(BufferDescriptorGetContentLock(bufHdr)));
+ Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
+ LW_EXCLUSIVE));
old_buf_state = pg_atomic_read_u32(&bufHdr->state);
for (;;)
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 53b45d72fe0..9d08de75ae5 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -1880,10 +1880,9 @@ LWLockReleaseAll(void)
/*
- * LWLockHeldByMe - test whether my process currently holds a lock
+ * LWLockHeldByMe - test whether my process holds a lock in any mode
*
- * This is meant as debug support only. We currently do not distinguish
- * whether the lock is held shared or exclusive.
+ * This is meant as debug support only.
*/
bool
LWLockHeldByMe(LWLock *l)
@@ -1897,3 +1896,21 @@ LWLockHeldByMe(LWLock *l)
}
return false;
}
+
+/*
+ * LWLockHeldByMeInMode - test whether my process holds a lock in given mode
+ *
+ * This is meant as debug support only.
+ */
+bool
+LWLockHeldByMeInMode(LWLock *l, LWLockMode mode)
+{
+ int i;
+
+ for (i = 0; i < num_held_lwlocks; i++)
+ {
+ if (held_lwlocks[i].lock == l && held_lwlocks[i].mode == mode)
+ return true;
+ }
+ return false;
+}
diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h
index 959f5f1e4d2..18931eb0469 100644
--- a/src/include/storage/lwlock.h
+++ b/src/include/storage/lwlock.h
@@ -175,6 +175,7 @@ extern void LWLockRelease(LWLock *lock);
extern void LWLockReleaseClearVar(LWLock *lock, uint64 *valptr, uint64 val);
extern void LWLockReleaseAll(void);
extern bool LWLockHeldByMe(LWLock *lock);
+extern bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode);
extern bool LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval);
extern void LWLockUpdateVar(LWLock *lock, uint64 *valptr, uint64 value);