Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit016abf1

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 parentec03f41 commit016abf1

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 processcurrentlyholds 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,LWLockModemode)
1907+
{
1908+
inti;
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
externvoidLWLockReleaseClearVar(LWLock*lock,uint64*valptr,uint64val);
176176
externvoidLWLockReleaseAll(void);
177177
externboolLWLockHeldByMe(LWLock*lock);
178+
externboolLWLockHeldByMeInMode(LWLock*lock,LWLockModemode);
178179

179180
externboolLWLockWaitForVar(LWLock*lock,uint64*valptr,uint64oldval,uint64*newval);
180181
externvoidLWLockUpdateVar(LWLock*lock,uint64*valptr,uint64value);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp