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

Commit0099b94

Browse files
committed
Convert confusing macros in multixact.c to static inline functions
The macros were confused about the argument data types. All thearguments were called 'xid', and some of the macros included casts toTransactionId, even though the arguments were actually eitherMultiXactIds or MultiXactOffsets. It compiles to the same thing,because TransactionId, MultiXactId and MultiXactOffset are alltypedefs of uint32, but it was highly misleading.Author: Maxim Orlov <orlovmg@gmail.com>Discussion:https://www.postgresql.org/message-id/CACG%3DezbLUG-OD1osAW3OchOMxZtdxHh2itYR9Zhh-a13wEBEQw%40mail.gmail.comDiscussion:https://www.postgresql.org/message-id/ff143b24-a093-40da-9833-d36b83726bdf%40iki.fi
1 parent92aff00 commit0099b94

File tree

1 file changed

+60
-19
lines changed

1 file changed

+60
-19
lines changed

‎src/backend/access/transam/multixact.c

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,23 @@
108108
/* We need four bytes per offset */
109109
#defineMULTIXACT_OFFSETS_PER_PAGE (BLCKSZ / sizeof(MultiXactOffset))
110110

111-
#defineMultiXactIdToOffsetPage(xid) \
112-
((xid) / (MultiXactOffset) MULTIXACT_OFFSETS_PER_PAGE)
113-
#defineMultiXactIdToOffsetEntry(xid) \
114-
((xid) % (MultiXactOffset) MULTIXACT_OFFSETS_PER_PAGE)
115-
#defineMultiXactIdToOffsetSegment(xid) (MultiXactIdToOffsetPage(xid) / SLRU_PAGES_PER_SEGMENT)
111+
staticinlineint64
112+
MultiXactIdToOffsetPage(MultiXactIdmulti)
113+
{
114+
returnmulti /MULTIXACT_OFFSETS_PER_PAGE;
115+
}
116+
117+
staticinlineint
118+
MultiXactIdToOffsetEntry(MultiXactIdmulti)
119+
{
120+
returnmulti %MULTIXACT_OFFSETS_PER_PAGE;
121+
}
122+
123+
staticinlineint
124+
MultiXactIdToOffsetSegment(MultiXactIdmulti)
125+
{
126+
returnMultiXactIdToOffsetPage(multi) /SLRU_PAGES_PER_SEGMENT;
127+
}
116128

117129
/*
118130
* The situation for members is a bit more complex: we store one byte of
@@ -156,30 +168,59 @@
156168
((uint32) ((0xFFFFFFFF % MULTIXACT_MEMBERS_PER_PAGE) + 1))
157169

158170
/* page in which a member is to be found */
159-
#defineMXOffsetToMemberPage(xid) ((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_PAGE)
160-
#defineMXOffsetToMemberSegment(xid) (MXOffsetToMemberPage(xid) / SLRU_PAGES_PER_SEGMENT)
171+
staticinlineint64
172+
MXOffsetToMemberPage(MultiXactOffsetoffset)
173+
{
174+
returnoffset /MULTIXACT_MEMBERS_PER_PAGE;
175+
}
176+
177+
staticinlineint
178+
MXOffsetToMemberSegment(MultiXactOffsetoffset)
179+
{
180+
returnMXOffsetToMemberPage(offset) /SLRU_PAGES_PER_SEGMENT;
181+
}
161182

162183
/* Location (byte offset within page) of flag word for a given member */
163-
#defineMXOffsetToFlagsOffset(xid) \
164-
((((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_MEMBERGROUP) % \
165-
(TransactionId) MULTIXACT_MEMBERGROUPS_PER_PAGE) * \
166-
(TransactionId) MULTIXACT_MEMBERGROUP_SIZE)
167-
#defineMXOffsetToFlagsBitShift(xid) \
168-
(((xid) % (TransactionId) MULTIXACT_MEMBERS_PER_MEMBERGROUP) * \
169-
MXACT_MEMBER_BITS_PER_XACT)
184+
staticinlineint
185+
MXOffsetToFlagsOffset(MultiXactOffsetoffset)
186+
{
187+
MultiXactOffsetgroup=offset /MULTIXACT_MEMBERS_PER_MEMBERGROUP;
188+
intgrouponpg=group %MULTIXACT_MEMBERGROUPS_PER_PAGE;
189+
intbyteoff=grouponpg*MULTIXACT_MEMBERGROUP_SIZE;
190+
191+
returnbyteoff;
192+
}
193+
194+
staticinlineint
195+
MXOffsetToFlagsBitShift(MultiXactOffsetoffset)
196+
{
197+
intmember_in_group=offset %MULTIXACT_MEMBERS_PER_MEMBERGROUP;
198+
intbshift=member_in_group*MXACT_MEMBER_BITS_PER_XACT;
199+
200+
returnbshift;
201+
}
170202

171203
/* Location (byte offset within page) of TransactionId of given member */
172-
#defineMXOffsetToMemberOffset(xid) \
173-
(MXOffsetToFlagsOffset(xid) + MULTIXACT_FLAGBYTES_PER_GROUP + \
174-
((xid) % MULTIXACT_MEMBERS_PER_MEMBERGROUP) * sizeof(TransactionId))
204+
staticinlineint
205+
MXOffsetToMemberOffset(MultiXactOffsetoffset)
206+
{
207+
intmember_in_group=offset %MULTIXACT_MEMBERS_PER_MEMBERGROUP;
208+
209+
returnMXOffsetToFlagsOffset(offset)+
210+
MULTIXACT_FLAGBYTES_PER_GROUP+
211+
member_in_group*sizeof(TransactionId);
212+
}
175213

176214
/* Multixact members wraparound thresholds. */
177215
#defineMULTIXACT_MEMBER_SAFE_THRESHOLD(MaxMultiXactOffset / 2)
178216
#defineMULTIXACT_MEMBER_DANGER_THRESHOLD\
179217
(MaxMultiXactOffset - MaxMultiXactOffset / 4)
180218

181-
#definePreviousMultiXactId(xid) \
182-
((xid) == FirstMultiXactId ? MaxMultiXactId : (xid) - 1)
219+
staticinlineMultiXactId
220+
PreviousMultiXactId(MultiXactIdmulti)
221+
{
222+
returnmulti==FirstMultiXactId ?MaxMultiXactId :multi-1;
223+
}
183224

184225
/*
185226
* Links to shared-memory data structures for MultiXact control

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp