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

Commite530be9

Browse files
committed
Remove duplicate reads from the inner loops in generic atomic ops.
The pg_atomic_compare_exchange_xxx functions are defined to update*expected to whatever they read from the target variable. Therefore,there's no need to do additional explicit reads after we've initializedthe "old" variable. The actual benefit of this is somewhat debatable,but it seems fairly unlikely to hurt anything, especially since wewill override the generic implementations in most performance-sensitivecases.Yura Sokolov, reviewed by Jesper Pedersen and myselfDiscussion:https://postgr.es/m/7f65886daca545067f82bf2b463b218d@postgrespro.ru
1 parent34ae182 commite530be9

File tree

1 file changed

+24
-48
lines changed

1 file changed

+24
-48
lines changed

‎src/include/port/atomics/generic.h

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ static inline uint32
170170
pg_atomic_exchange_u32_impl(volatilepg_atomic_uint32*ptr,uint32xchg_)
171171
{
172172
uint32old;
173-
while (true)
174-
{
175-
old=pg_atomic_read_u32_impl(ptr);
176-
if (pg_atomic_compare_exchange_u32_impl(ptr,&old,xchg_))
177-
break;
178-
}
173+
old=pg_atomic_read_u32_impl(ptr);
174+
while (!pg_atomic_compare_exchange_u32_impl(ptr,&old,xchg_))
175+
/* skip */;
179176
returnold;
180177
}
181178
#endif
@@ -186,12 +183,9 @@ static inline uint32
186183
pg_atomic_fetch_add_u32_impl(volatilepg_atomic_uint32*ptr,int32add_)
187184
{
188185
uint32old;
189-
while (true)
190-
{
191-
old=pg_atomic_read_u32_impl(ptr);
192-
if (pg_atomic_compare_exchange_u32_impl(ptr,&old,old+add_))
193-
break;
194-
}
186+
old=pg_atomic_read_u32_impl(ptr);
187+
while (!pg_atomic_compare_exchange_u32_impl(ptr,&old,old+add_))
188+
/* skip */;
195189
returnold;
196190
}
197191
#endif
@@ -211,12 +205,9 @@ static inline uint32
211205
pg_atomic_fetch_and_u32_impl(volatilepg_atomic_uint32*ptr,uint32and_)
212206
{
213207
uint32old;
214-
while (true)
215-
{
216-
old=pg_atomic_read_u32_impl(ptr);
217-
if (pg_atomic_compare_exchange_u32_impl(ptr,&old,old&and_))
218-
break;
219-
}
208+
old=pg_atomic_read_u32_impl(ptr);
209+
while (!pg_atomic_compare_exchange_u32_impl(ptr,&old,old&and_))
210+
/* skip */;
220211
returnold;
221212
}
222213
#endif
@@ -227,12 +218,9 @@ static inline uint32
227218
pg_atomic_fetch_or_u32_impl(volatilepg_atomic_uint32*ptr,uint32or_)
228219
{
229220
uint32old;
230-
while (true)
231-
{
232-
old=pg_atomic_read_u32_impl(ptr);
233-
if (pg_atomic_compare_exchange_u32_impl(ptr,&old,old |or_))
234-
break;
235-
}
221+
old=pg_atomic_read_u32_impl(ptr);
222+
while (!pg_atomic_compare_exchange_u32_impl(ptr,&old,old |or_))
223+
/* skip */;
236224
returnold;
237225
}
238226
#endif
@@ -261,12 +249,9 @@ static inline uint64
261249
pg_atomic_exchange_u64_impl(volatilepg_atomic_uint64*ptr,uint64xchg_)
262250
{
263251
uint64old;
264-
while (true)
265-
{
266-
old=ptr->value;
267-
if (pg_atomic_compare_exchange_u64_impl(ptr,&old,xchg_))
268-
break;
269-
}
252+
old=ptr->value;
253+
while (!pg_atomic_compare_exchange_u64_impl(ptr,&old,xchg_))
254+
/* skip */;
270255
returnold;
271256
}
272257
#endif
@@ -357,12 +342,9 @@ static inline uint64
357342
pg_atomic_fetch_add_u64_impl(volatilepg_atomic_uint64*ptr,int64add_)
358343
{
359344
uint64old;
360-
while (true)
361-
{
362-
old=pg_atomic_read_u64_impl(ptr);
363-
if (pg_atomic_compare_exchange_u64_impl(ptr,&old,old+add_))
364-
break;
365-
}
345+
old=pg_atomic_read_u64_impl(ptr);
346+
while (!pg_atomic_compare_exchange_u64_impl(ptr,&old,old+add_))
347+
/* skip */;
366348
returnold;
367349
}
368350
#endif
@@ -382,12 +364,9 @@ static inline uint64
382364
pg_atomic_fetch_and_u64_impl(volatilepg_atomic_uint64*ptr,uint64and_)
383365
{
384366
uint64old;
385-
while (true)
386-
{
387-
old=pg_atomic_read_u64_impl(ptr);
388-
if (pg_atomic_compare_exchange_u64_impl(ptr,&old,old&and_))
389-
break;
390-
}
367+
old=pg_atomic_read_u64_impl(ptr);
368+
while (!pg_atomic_compare_exchange_u64_impl(ptr,&old,old&and_))
369+
/* skip */;
391370
returnold;
392371
}
393372
#endif
@@ -398,12 +377,9 @@ static inline uint64
398377
pg_atomic_fetch_or_u64_impl(volatilepg_atomic_uint64*ptr,uint64or_)
399378
{
400379
uint64old;
401-
while (true)
402-
{
403-
old=pg_atomic_read_u64_impl(ptr);
404-
if (pg_atomic_compare_exchange_u64_impl(ptr,&old,old |or_))
405-
break;
406-
}
380+
old=pg_atomic_read_u64_impl(ptr);
381+
while (!pg_atomic_compare_exchange_u64_impl(ptr,&old,old |or_))
382+
/* skip */;
407383
returnold;
408384
}
409385
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp