Skip to content

Commit 016abf1

Browse files
Add debug check function LWLockHeldByMeInMode()
Tests whether my process holds a lock in given mode. Add initial usage in MarkBufferDirty(). Thomas Munro
1 parent ec03f41 commit 016abf1

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,8 @@ MarkBufferDirty(Buffer buffer)
14601460
bufHdr = GetBufferDescriptor(buffer - 1);
14611461

14621462
Assert(BufferIsPinned(buffer));
1463-
/* unfortunately we can't check if the lock is held exclusively */
1464-
Assert(LWLockHeldByMe(BufferDescriptorGetContentLock(bufHdr)));
1463+
Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
1464+
LW_EXCLUSIVE));
14651465

14661466
old_buf_state = pg_atomic_read_u32(&bufHdr->state);
14671467
for (;;)

src/backend/storage/lmgr/lwlock.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,10 +1880,9 @@ LWLockReleaseAll(void)
18801880

18811881

18821882
/*
1883-
* LWLockHeldByMe - test whether my process currently holds a lock
1883+
* LWLockHeldByMe - test whether my process holds a lock in any mode
18841884
*
1885-
* This is meant as debug support only. We currently do not distinguish
1886-
* whether the lock is held shared or exclusive.
1885+
* This is meant as debug support only.
18871886
*/
18881887
bool
18891888
LWLockHeldByMe(LWLock *l)
@@ -1897,3 +1896,21 @@ LWLockHeldByMe(LWLock *l)
18971896
}
18981897
return false;
18991898
}
1899+
1900+
/*
1901+
* LWLockHeldByMeInMode - test whether my process holds a lock in given mode
1902+
*
1903+
* This is meant as debug support only.
1904+
*/
1905+
bool
1906+
LWLockHeldByMeInMode(LWLock *l, LWLockMode mode)
1907+
{
1908+
int i;
1909+
1910+
for (i = 0; i < num_held_lwlocks; i++)
1911+
{
1912+
if (held_lwlocks[i].lock == l && held_lwlocks[i].mode == mode)
1913+
return true;
1914+
}
1915+
return false;
1916+
}

src/include/storage/lwlock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ extern void LWLockRelease(LWLock *lock);
175175
extern void LWLockReleaseClearVar(LWLock *lock, uint64 *valptr, uint64 val);
176176
extern void LWLockReleaseAll(void);
177177
extern bool LWLockHeldByMe(LWLock *lock);
178+
extern bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode);
178179

179180
extern bool LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval);
180181
extern void LWLockUpdateVar(LWLock *lock, uint64 *valptr, uint64 value);

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