utils: Use GCC's __atomic built-ins if available
These are available since GCC 4.7 and will eventually replace the __sync operations. They support the memory model defined by C++11. For instance, by using __ATOMIC_RELAXED for some operations on the reference counters we can avoid memory barriers, which are required by __sync operations (whose memory model essentially is __ATOMIC_SEQ_CST).
This commit is contained in:
+25
-7
@@ -667,21 +667,39 @@ AC_COMPILE_IFELSE(
|
||||
[AC_MSG_RESULT([no])]
|
||||
)
|
||||
|
||||
AC_MSG_CHECKING([for gcc atomic operations])
|
||||
AC_MSG_CHECKING([for GCC __atomic operations])
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[[
|
||||
int main() {
|
||||
volatile int ref = 1;
|
||||
__sync_fetch_and_add (&ref, 1);
|
||||
__sync_sub_and_fetch (&ref, 1);
|
||||
/* Make sure test fails if operations are not supported */
|
||||
__sync_val_compare_and_swap(&ref, 1, 0);
|
||||
int ref = 1, val;
|
||||
__atomic_fetch_add(&ref, 1, __ATOMIC_RELAXED);
|
||||
val = __atomic_sub_fetch(&ref, 1, __ATOMIC_RELAXED);
|
||||
__atomic_compare_exchange_n(&ref, &val, 0, 0, __ATOMIC_RELAXED,
|
||||
__ATOMIC_RELAXED);
|
||||
return ref;
|
||||
}
|
||||
]])],
|
||||
[AC_MSG_RESULT([yes]);
|
||||
AC_DEFINE([HAVE_GCC_ATOMIC_OPERATIONS], [],
|
||||
[have GCC __sync_* atomic operations])],
|
||||
[have GCC __atomic_* operations])],
|
||||
[AC_MSG_RESULT([no])],
|
||||
[AC_MSG_RESULT([no])]
|
||||
)
|
||||
|
||||
AC_MSG_CHECKING([for GCC __sync operations])
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[[
|
||||
int main() {
|
||||
int ref = 1;
|
||||
__sync_fetch_and_add (&ref, 1);
|
||||
__sync_sub_and_fetch (&ref, 1);
|
||||
__sync_val_compare_and_swap(&ref, 1, 0);
|
||||
return ref;
|
||||
}
|
||||
]])],
|
||||
[AC_MSG_RESULT([yes]);
|
||||
AC_DEFINE([HAVE_GCC_SYNC_OPERATIONS], [],
|
||||
[have GCC __sync_* operations])],
|
||||
[AC_MSG_RESULT([no])],
|
||||
[AC_MSG_RESULT([no])]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user