Debian Codegraph @

m4/atomic_operations.m4

raw
1 # rsyslog
2 #
3 # atomic_operations.m4 - autoconf macro to check if compiler supports atomic
4 # operations
5 #
6 # rgerhards, 2008-09-18, added based on
7 # http://svn.apache.org/repos/asf/apr/apr/trunk/configure.in
8 #
9 #
10 AC_DEFUN([RS_ATOMIC_OPERATIONS],
11 [AC_CACHE_CHECK([whether the compiler provides atomic builtins], [ap_cv_atomic_builtins],
12 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
13 unsigned long val = 1010, tmp, *mem = &val;
14
15 if (__sync_fetch_and_add(&val, 1010) != 1010 || val != 2020)
16 return 1;
17
18 tmp = val;
19
20 if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010)
21 return 1;
22
23 if (__sync_sub_and_fetch(&val, 1010) != 0 || val != 0)
24 return 1;
25
26 tmp = 3030;
27
28 if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp)
29 return 1;
30
31 if (__sync_lock_test_and_set(&val, 4040) != 3030)
32 return 1;
33
34 mem = &tmp;
35
36 if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp)
37 return 1;
38
39 __sync_synchronize();
40
41 if (mem != &val)
42 return 1;
43
44 return 0;
45 ]])], [ap_cv_atomic_builtins=yes], [ap_cv_atomic_builtins=no])])
46
47 if test "$ap_cv_atomic_builtins" = "yes"; then
48 AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins])
49 fi
50
51 ])