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

Commit3a9d0d7

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 parent1c9acb1 commit3a9d0d7

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
@@ -509,7 +509,6 @@ pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr,
509509
{
510510
#ifndefPG_HAVE_ATOMIC_U64_SIMULATION
511511
AssertPointerAlignment(ptr,8);
512-
AssertPointerAlignment(expected,8);
513512
#endif
514513
returnpg_atomic_compare_exchange_u64_impl(ptr,expected,newval);
515514
}
@@ -578,7 +577,7 @@ pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
578577
* Full barrier semantics (even when value is unchanged).
579578
*/
580579
staticinlineuint64
581-
pg_atomic_monotonic_advance_u64(volatilepg_atomic_uint64*ptr,uint64target_)
580+
pg_atomic_monotonic_advance_u64(volatilepg_atomic_uint64*ptr,uint64target)
582581
{
583582
uint64currval;
584583

@@ -587,23 +586,19 @@ pg_atomic_monotonic_advance_u64(volatile pg_atomic_uint64 *ptr, uint64 target_)
587586
#endif
588587

589588
currval=pg_atomic_read_u64_impl(ptr);
590-
if (currval >=target_)
589+
if (currval >=target)
591590
{
592591
pg_memory_barrier();
593592
returncurrval;
594593
}
595594

596-
#ifndefPG_HAVE_ATOMIC_U64_SIMULATION
597-
AssertPointerAlignment(&currval,8);
598-
#endif
599-
600-
while (currval<target_)
595+
while (currval<target)
601596
{
602-
if (pg_atomic_compare_exchange_u64_impl(ptr,&currval,target_))
603-
break;
597+
if (pg_atomic_compare_exchange_u64(ptr,&currval,target))
598+
returntarget;
604599
}
605600

606-
returnMax(target_,currval);
601+
returncurrval;
607602
}
608603

609604
#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