xref: /unit/auto/atomic (revision 0:a63ceefd6ab0)
1
2# Copyright (C) Igor Sysoev
3# Copyright (C) NGINX, Inc.
4
5
6# GCC 4.1+ builtin atomic operations.
7
8nxt_feature="GCC builtin atomic operations"
9nxt_feature_name=NXT_HAVE_GCC_ATOMIC
10nxt_feature_run=yes
11nxt_feature_incs=
12nxt_feature_libs=
13nxt_feature_test="int main() {
14                      long  n = 0;
15
16                      if (!__sync_bool_compare_and_swap(&n, 0, 3))
17                          return 1;
18                      if (__sync_fetch_and_add(&n, 1) != 3)
19                          return 1;
20                      if (__sync_lock_test_and_set(&n, 5) != 4)
21                          return 1;
22                      if (n != 5)
23                          return 1;
24                      __sync_lock_release(&n);
25                      if (n != 0)
26                          return 1;
27                      return 0;
28                  }"
29. auto/feature
30
31
32# Solaris 10 builtin atomic operations.
33
34if [ $nxt_found = no ]; then
35
36    nxt_feature="Solaris builtin atomic operations"
37    nxt_feature_name=NXT_HAVE_SOLARIS_ATOMIC
38    nxt_feature_run=yes
39    nxt_feature_incs=
40    nxt_feature_libs=
41    nxt_feature_test="#include <atomic.h>
42
43                      int main() {
44                          ulong_t  n = 0;
45
46                          if (atomic_cas_ulong(&n, 0, 3) != 0)
47                              return 1;
48                          if (atomic_add_long_nv(&n, 1) != 4)
49                              return 1;
50                          if (atomic_swap_ulong(&n, 5) != 4)
51                              return 1;
52                          if (n != 5)
53                              return 1;
54                          return 0;
55                      }"
56    . auto/feature
57fi
58
59
60# AIX xlC builtin atomic operations.
61
62if [ $nxt_found = no ]; then
63
64    if [ $NXT_64BIT = 1 ]; then
65        nxt_feature_test="int main() {
66                              long  n = 0;
67                              long  o = 0;
68
69                              if (!__compare_and_swaplp(&n, &o, 3))
70                                  return 1;
71                              if (__fetch_and_addlp(&n, 1) != 3)
72                                  return 1;
73                              if (__fetch_and_swaplp(&n, 5) != 4)
74                                  return 1;
75                              if (n != 5)
76                                  return 1;
77                              __isync();
78                              __lwsync();
79                              return 0;
80                          }"
81    else
82        nxt_feature_test="int main() {
83                              int  n = 0;
84                              int  o = 0;
85
86                              if (!__compare_and_swap(&n, &o, 3))
87                                  return 1;
88                              if (__fetch_and_add(&n, 1) != 3)
89                                  return 1;
90                              if (__fetch_and_swap(&n, 5) != 4)
91                                  return 1;
92                              if (n != 5)
93                                  return 1;
94                              __isync();
95                              __lwsync();
96                              return 0;
97                          }"
98    fi
99
100    nxt_feature="xlC builtin atomic operations"
101    nxt_feature_name=NXT_HAVE_XLC_ATOMIC
102    nxt_feature_run=yes
103    nxt_feature_incs=
104    nxt_feature_libs=
105    . auto/feature
106fi
107
108
109if [ $nxt_found = no ]; then
110    $echo
111    $echo $0: error: no atomic operations found.
112    $echo
113    exit 1;
114fi
115