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

Commit698127a

Browse files
committed
Prefer int-wide pg_atomic_flag over char-wide when using gcc intrinsics.
configure can only probe the existence of gcc intrinsics, not how wellthey're implemented, and unfortunately the answer is sometimes "badly".In particular we've found that multiple compilers fail to implementchar-width __sync_lock_test_and_set() correctly on PPC; and even a correctimplementation would necessarily be pretty inefficient, since that hardwarehas only a word-wide primitive to work with.Given the knowledge we've accumulated in s_lock.h, it appears that it'sbest to rely on int-width TAS operations on most non-Intel architectures.Hence, pick int not char when both are nominally available to us ingeneric-gcc.h (note that that code is not used for x86[_64]).Back-patch to fix regression test failures on FreeBSD/PPC. Ordinarilyback-patching a change like this would be verboten because of ABI breakage.But since pg_atomic_flag is not yet used in any Postgres data structure,there's no ABI to break. It seems safer to back-patch to avoid possiblegotchas, if someday we do back-patch something that uses pg_atomic_flag.Discussion:https://postgr.es/m/25414.1483076673@sss.pgh.pa.us
1 parent345b2dc commit698127a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@
6262
#definePG_HAVE_ATOMIC_FLAG_SUPPORT
6363
typedefstructpg_atomic_flag
6464
{
65-
/* some platforms only have a 8 bit wide TAS */
66-
#ifdefHAVE_GCC__SYNC_CHAR_TAS
67-
volatilecharvalue;
68-
#else
69-
/* but an int works on more platforms */
65+
/*
66+
* If we have a choice, use int-width TAS, because that is more efficient
67+
* and/or more reliably implemented on most non-Intel platforms. (Note
68+
* that this code isn't used on x86[_64]; see arch-x86.h for that.)
69+
*/
70+
#ifdefHAVE_GCC__SYNC_INT32_TAS
7071
volatileintvalue;
72+
#else
73+
volatilecharvalue;
7174
#endif
7275
}pg_atomic_flag;
7376

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp