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

Commit768f0c3

Browse files
committed
Remove bogus assertion in pg_atomic_monotonic_advance_u64
This code wanted to ensure that the 'exchange' variable passed topg_atomic_compare_exchange_u64 has correct alignment, but apparentlyplatforms don't actually require anything that doesn't come naturally.While messing with pg_atomic_monotonic_advance_u64: instead of usingMax() to determine the value to return, just usepg_atomic_compare_exchange_u64()'s return value to decide; also, usepg_atomic_compare_exchange_u64 instead of the _impl version; also removethe unnecessary underscore at the end of variable name "target".Backpatch to 17, where this code was introduced by commit bf3ff7bf83bc.Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/36796438-a718-cf9b-2071-b2c1b947c1b5@gmail.com
1 parentab0ae64 commit768f0c3

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

‎src/include/port/atomics.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr,
507507
{
508508
#ifndefPG_HAVE_ATOMIC_U64_SIMULATION
509509
AssertPointerAlignment(ptr,8);
510-
AssertPointerAlignment(expected,8);
511510
#endif
512511
returnpg_atomic_compare_exchange_u64_impl(ptr,expected,newval);
513512
}
@@ -576,7 +575,7 @@ pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
576575
* Full barrier semantics (even when value is unchanged).
577576
*/
578577
staticinlineuint64
579-
pg_atomic_monotonic_advance_u64(volatilepg_atomic_uint64*ptr,uint64target_)
578+
pg_atomic_monotonic_advance_u64(volatilepg_atomic_uint64*ptr,uint64target)
580579
{
581580
uint64currval;
582581

@@ -585,23 +584,19 @@ pg_atomic_monotonic_advance_u64(volatile pg_atomic_uint64 *ptr, uint64 target_)
585584
#endif
586585

587586
currval=pg_atomic_read_u64_impl(ptr);
588-
if (currval >=target_)
587+
if (currval >=target)
589588
{
590589
pg_memory_barrier();
591590
returncurrval;
592591
}
593592

594-
#ifndefPG_HAVE_ATOMIC_U64_SIMULATION
595-
AssertPointerAlignment(&currval,8);
596-
#endif
597-
598-
while (currval<target_)
593+
while (currval<target)
599594
{
600-
if (pg_atomic_compare_exchange_u64_impl(ptr,&currval,target_))
601-
break;
595+
if (pg_atomic_compare_exchange_u64(ptr,&currval,target))
596+
returntarget;
602597
}
603598

604-
returnMax(target_,currval);
599+
returncurrval;
605600
}
606601

607602
#undef INSIDE_ATOMICS_H

‎src/include/port/atomics/arch-ppc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
173173
uint32condition_register;
174174
boolret;
175175

176+
AssertPointerAlignment(expected,8);
177+
176178
/* Like u32, but s/lwarx/ldarx/; s/stwcx/stdcx/; s/cmpw/cmpd/ */
177179
#ifdefHAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P
178180
if (__builtin_constant_p(*expected)&&

‎src/include/port/atomics/arch-x86.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
207207
{
208208
charret;
209209

210+
AssertPointerAlignment(expected,8);
211+
210212
/*
211213
* Perform cmpxchg and use the zero flag which it implicitly sets when
212214
* equal to measure the success.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static inline bool
240240
pg_atomic_compare_exchange_u64_impl(volatilepg_atomic_uint64*ptr,
241241
uint64*expected,uint64newval)
242242
{
243+
AssertPointerAlignment(expected,8);
243244
return__atomic_compare_exchange_n(&ptr->value,expected,newval, false,
244245
__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST);
245246
}
@@ -253,6 +254,8 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
253254
{
254255
boolret;
255256
uint64current;
257+
258+
AssertPointerAlignment(expected,8);
256259
current=__sync_val_compare_and_swap(&ptr->value,*expected,newval);
257260
ret=current==*expected;
258261
*expected=current;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
102102
boolret;
103103
uint64current;
104104

105+
AssertPointerAlignment(expected,8);
105106
current=atomic_cas_64(&ptr->value,*expected,newval);
106107
ret=current==*expected;
107108
*expected=current;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp