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

Commitcd3ccf8

Browse files
committed
Base LWLock limits directly on MAX_BACKENDS
Jacob reported that comments for LW_SHARED_MASK referenced a MAX_BACKENDSlimit of 2^23-1, but that MAX_BACKENDS is actually limited to 2^18-1. Thelimit was lowered in4835458, but the comment in lwlock.c wasn't updated.Instead of just fixing the comment, it seems better to directly base thelwlock defines on MAX_BACKENDS and add static assertions to ensure that thereis enough space. That way there's no comment that can go out of sync in thefuture.As part of that change I noticed that for some reason the high bit wasn't usedfor flags, which seems somewhat odd. Redefine the flag values to start at thehighest bit.Reported-by: Jacob Brazeal <jacob.brazeal@gmail.com>Reviewed-by: Jacob Brazeal <jacob.brazeal@gmail.com>Discussion:https://postgr.es/m/CA+COZaBO_s3LfALq=b+HcBHFSOEGiApVjrRacCe4VP9m7CJsNQ@mail.gmail.com
1 parent6394a3a commitcd3ccf8

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

‎src/backend/storage/lmgr/lwlock.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,29 @@
9191
#endif
9292

9393

94-
#defineLW_FLAG_HAS_WAITERS((uint32) 1 << 30)
95-
#defineLW_FLAG_RELEASE_OK((uint32) 1 << 29)
96-
#defineLW_FLAG_LOCKED((uint32) 1 << 28)
97-
98-
#defineLW_VAL_EXCLUSIVE((uint32) 1 << 24)
94+
#defineLW_FLAG_HAS_WAITERS((uint32) 1 << 31)
95+
#defineLW_FLAG_RELEASE_OK((uint32) 1 << 30)
96+
#defineLW_FLAG_LOCKED((uint32) 1 << 29)
97+
#defineLW_FLAG_BITS3
98+
#defineLW_FLAG_MASK(((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS))
99+
100+
/* assumes MAX_BACKENDS is a (power of 2) - 1, checked below */
101+
#defineLW_VAL_EXCLUSIVE(MAX_BACKENDS + 1)
99102
#defineLW_VAL_SHARED1
100103

101-
#defineLW_LOCK_MASK((uint32) ((1 << 25)-1))
102-
/* Must be greater than MAX_BACKENDS - which is 2^23-1, so we're fine. */
103-
#defineLW_SHARED_MASK((uint32) ((1 << 24)-1))
104+
/* already (power of 2)-1, i.e. suitable for a mask */
105+
#defineLW_SHARED_MASKMAX_BACKENDS
106+
#defineLW_LOCK_MASK(MAX_BACKENDS | LW_VAL_EXCLUSIVE)
107+
108+
109+
StaticAssertDecl(((MAX_BACKENDS+1)&MAX_BACKENDS)==0,
110+
"MAX_BACKENDS + 1 needs to be a power of 2");
111+
112+
StaticAssertDecl((MAX_BACKENDS&LW_FLAG_MASK)==0,
113+
"MAX_BACKENDS and LW_FLAG_MASK overlap");
104114

105-
StaticAssertDecl(LW_VAL_EXCLUSIVE> (uint32)MAX_BACKENDS,
106-
"MAX_BACKENDS too big for lwlock.c");
115+
StaticAssertDecl((LW_VAL_EXCLUSIVE&LW_FLAG_MASK)==0,
116+
"LW_VAL_EXCLUSIVE and LW_FLAG_MASK overlap");
107117

108118
/*
109119
* There are three sorts of LWLock "tranches":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp