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

Commit0a41e86

Browse files
committed
Use __sync_lock_test_and_set() for spinlocks on ARM, if available.
Historically we've used the SWPB instruction for TAS() on ARM, but thisis deprecated and not available on ARMv6 and later. Instead, make useof a GCC builtin if available. We'll still fall back to SWPB if not,so as not to break existing ports using older GCC versions.Eventually we might want to try using __sync_lock_test_and_set() on someother architectures too, but for now that seems to present only risk andnot reward.Back-patch to all supported versions, since people might want to use anyof them on more recent ARM chips.Martin Pitt
1 parent1fc3d18 commit0a41e86

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

‎configure

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22596,6 +22596,71 @@ fi
2259622596
done
2259722597

2259822598

22599+
{ $as_echo "$as_me:$LINENO: checking for builtin locking functions" >&5
22600+
$as_echo_n "checking for builtin locking functions... " >&6; }
22601+
if test "${pgac_cv_gcc_int_atomics+set}" = set; then
22602+
$as_echo_n "(cached) " >&6
22603+
else
22604+
cat >conftest.$ac_ext <<_ACEOF
22605+
/* confdefs.h. */
22606+
_ACEOF
22607+
cat confdefs.h >>conftest.$ac_ext
22608+
cat >>conftest.$ac_ext <<_ACEOF
22609+
/* end confdefs.h. */
22610+
22611+
int
22612+
main ()
22613+
{
22614+
int lock = 0;
22615+
__sync_lock_test_and_set(&lock, 1);
22616+
__sync_lock_release(&lock);
22617+
;
22618+
return 0;
22619+
}
22620+
_ACEOF
22621+
rm -f conftest.$ac_objext conftest$ac_exeext
22622+
if { (ac_try="$ac_link"
22623+
case "(($ac_try" in
22624+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
22625+
*) ac_try_echo=$ac_try;;
22626+
esac
22627+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
22628+
$as_echo "$ac_try_echo") >&5
22629+
(eval "$ac_link") 2>conftest.er1
22630+
ac_status=$?
22631+
grep -v '^ *+' conftest.er1 >conftest.err
22632+
rm -f conftest.er1
22633+
cat conftest.err >&5
22634+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
22635+
(exit $ac_status); } && {
22636+
test -z "$ac_c_werror_flag" ||
22637+
test ! -s conftest.err
22638+
} && test -s conftest$ac_exeext && {
22639+
test "$cross_compiling" = yes ||
22640+
$as_test_x conftest$ac_exeext
22641+
}; then
22642+
pgac_cv_gcc_int_atomics="yes"
22643+
else
22644+
$as_echo "$as_me: failed program was:" >&5
22645+
sed 's/^/| /' conftest.$ac_ext >&5
22646+
22647+
pgac_cv_gcc_int_atomics="no"
22648+
fi
22649+
22650+
rm -rf conftest.dSYM
22651+
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
22652+
conftest$ac_exeext conftest.$ac_ext
22653+
fi
22654+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_gcc_int_atomics" >&5
22655+
$as_echo "$pgac_cv_gcc_int_atomics" >&6; }
22656+
if test x"$pgac_cv_gcc_int_atomics" = x"yes"; then
22657+
22658+
cat >>confdefs.h <<\_ACEOF
22659+
#define HAVE_GCC_INT_ATOMICS 1
22660+
_ACEOF
22661+
22662+
fi
22663+
2259922664

2260022665
#
2260122666
# Pthreads

‎configure.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,17 @@ fi
14541454
AC_CHECK_FUNCS([strtoll strtoq], [break])
14551455
AC_CHECK_FUNCS([strtoull strtouq], [break])
14561456

1457+
AC_CACHE_CHECK([for builtin locking functions], pgac_cv_gcc_int_atomics,
1458+
[AC_TRY_LINK([],
1459+
[int lock = 0;
1460+
__sync_lock_test_and_set(&lock, 1);
1461+
__sync_lock_release(&lock);],
1462+
[pgac_cv_gcc_int_atomics="yes"],
1463+
[pgac_cv_gcc_int_atomics="no"])])
1464+
if test x"$pgac_cv_gcc_int_atomics" = x"yes"; then
1465+
AC_DEFINE(HAVE_GCC_INT_ATOMICS, 1, [Define to 1 if you have __sync_lock_test_and_set(int *) and friends.])
1466+
fi
1467+
14571468

14581469
#
14591470
# Pthreads

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
/* Define to 1 if your compiler understands __FUNCTION__. */
180180
#undef HAVE_FUNCNAME__FUNCTION
181181

182+
/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */
183+
#undef HAVE_GCC_INT_ATOMICS
184+
182185
/* Define to 1 if you have the `getaddrinfo' function. */
183186
#undef HAVE_GETADDRINFO
184187

‎src/include/storage/s_lock.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,33 @@ tas(volatile slock_t *lock)
275275
#endif/* __ia64__ || __ia64 */
276276

277277

278+
/*
279+
* On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if
280+
* not fall back on the SWPB instruction. SWPB does not work on ARMv6 or
281+
* later, so the compiler builtin is preferred if available. Note also that
282+
* the int-width variant of the builtin works on more chips than other widths.
283+
*/
278284
#if defined(__arm__)|| defined(__arm)
279285
#defineHAS_TEST_AND_SET
280286

281-
typedefunsignedcharslock_t;
282-
283287
#defineTAS(lock) tas(lock)
284288

289+
#ifdefHAVE_GCC_INT_ATOMICS
290+
291+
typedefintslock_t;
292+
293+
static __inline__int
294+
tas(volatileslock_t*lock)
295+
{
296+
return__sync_lock_test_and_set(lock,1);
297+
}
298+
299+
#defineS_UNLOCK(lock) __sync_lock_release(lock)
300+
301+
#else/* !HAVE_GCC_INT_ATOMICS */
302+
303+
typedefunsignedcharslock_t;
304+
285305
static __inline__int
286306
tas(volatileslock_t*lock)
287307
{
@@ -295,6 +315,7 @@ tas(volatile slock_t *lock)
295315
return (int)_res;
296316
}
297317

318+
#endif/* HAVE_GCC_INT_ATOMICS */
298319
#endif/* __arm__ */
299320

300321

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp