xref: /unit/auto/atomic (revision 37:7ef020869079)
10Sigor@sysoev.ru
20Sigor@sysoev.ru# Copyright (C) Igor Sysoev
30Sigor@sysoev.ru# Copyright (C) NGINX, Inc.
40Sigor@sysoev.ru
50Sigor@sysoev.ru
60Sigor@sysoev.ru# GCC 4.1+ builtin atomic operations.
70Sigor@sysoev.ru
80Sigor@sysoev.runxt_feature="GCC builtin atomic operations"
90Sigor@sysoev.runxt_feature_name=NXT_HAVE_GCC_ATOMIC
100Sigor@sysoev.runxt_feature_run=yes
110Sigor@sysoev.runxt_feature_incs=
120Sigor@sysoev.runxt_feature_libs=
130Sigor@sysoev.runxt_feature_test="int main() {
140Sigor@sysoev.ru                      long  n = 0;
150Sigor@sysoev.ru
160Sigor@sysoev.ru                      if (!__sync_bool_compare_and_swap(&n, 0, 3))
170Sigor@sysoev.ru                          return 1;
180Sigor@sysoev.ru                      if (__sync_fetch_and_add(&n, 1) != 3)
190Sigor@sysoev.ru                          return 1;
200Sigor@sysoev.ru                      if (__sync_lock_test_and_set(&n, 5) != 4)
210Sigor@sysoev.ru                          return 1;
220Sigor@sysoev.ru                      if (n != 5)
230Sigor@sysoev.ru                          return 1;
24*37Smax.romanov@nginx.com                      if (__sync_or_and_fetch(&n, 2) != 7)
25*37Smax.romanov@nginx.com                          return 1;
26*37Smax.romanov@nginx.com                      if (__sync_and_and_fetch(&n, 5) != 5)
27*37Smax.romanov@nginx.com                          return 1;
280Sigor@sysoev.ru                      __sync_lock_release(&n);
290Sigor@sysoev.ru                      if (n != 0)
300Sigor@sysoev.ru                          return 1;
310Sigor@sysoev.ru                      return 0;
320Sigor@sysoev.ru                  }"
330Sigor@sysoev.ru. auto/feature
340Sigor@sysoev.ru
350Sigor@sysoev.ru
360Sigor@sysoev.ru# Solaris 10 builtin atomic operations.
370Sigor@sysoev.ru
380Sigor@sysoev.ruif [ $nxt_found = no ]; then
390Sigor@sysoev.ru
400Sigor@sysoev.ru    nxt_feature="Solaris builtin atomic operations"
410Sigor@sysoev.ru    nxt_feature_name=NXT_HAVE_SOLARIS_ATOMIC
420Sigor@sysoev.ru    nxt_feature_run=yes
430Sigor@sysoev.ru    nxt_feature_incs=
440Sigor@sysoev.ru    nxt_feature_libs=
450Sigor@sysoev.ru    nxt_feature_test="#include <atomic.h>
460Sigor@sysoev.ru
470Sigor@sysoev.ru                      int main() {
480Sigor@sysoev.ru                          ulong_t  n = 0;
490Sigor@sysoev.ru
500Sigor@sysoev.ru                          if (atomic_cas_ulong(&n, 0, 3) != 0)
510Sigor@sysoev.ru                              return 1;
520Sigor@sysoev.ru                          if (atomic_add_long_nv(&n, 1) != 4)
530Sigor@sysoev.ru                              return 1;
540Sigor@sysoev.ru                          if (atomic_swap_ulong(&n, 5) != 4)
550Sigor@sysoev.ru                              return 1;
560Sigor@sysoev.ru                          if (n != 5)
570Sigor@sysoev.ru                              return 1;
58*37Smax.romanov@nginx.com                          if (atomic_or_ulong_nv(&n, 2) != 7)
59*37Smax.romanov@nginx.com                              return 1;
60*37Smax.romanov@nginx.com                          if (atomic_and_ulong_nv(&n, 5) != 5)
61*37Smax.romanov@nginx.com                              return 1;
620Sigor@sysoev.ru                          return 0;
630Sigor@sysoev.ru                      }"
640Sigor@sysoev.ru    . auto/feature
650Sigor@sysoev.rufi
660Sigor@sysoev.ru
670Sigor@sysoev.ru
680Sigor@sysoev.ru# AIX xlC builtin atomic operations.
690Sigor@sysoev.ru
700Sigor@sysoev.ruif [ $nxt_found = no ]; then
710Sigor@sysoev.ru
720Sigor@sysoev.ru    if [ $NXT_64BIT = 1 ]; then
730Sigor@sysoev.ru        nxt_feature_test="int main() {
740Sigor@sysoev.ru                              long  n = 0;
750Sigor@sysoev.ru                              long  o = 0;
760Sigor@sysoev.ru
770Sigor@sysoev.ru                              if (!__compare_and_swaplp(&n, &o, 3))
780Sigor@sysoev.ru                                  return 1;
790Sigor@sysoev.ru                              if (__fetch_and_addlp(&n, 1) != 3)
800Sigor@sysoev.ru                                  return 1;
810Sigor@sysoev.ru                              if (__fetch_and_swaplp(&n, 5) != 4)
820Sigor@sysoev.ru                                  return 1;
830Sigor@sysoev.ru                              if (n != 5)
840Sigor@sysoev.ru                                  return 1;
850Sigor@sysoev.ru                              __isync();
860Sigor@sysoev.ru                              __lwsync();
870Sigor@sysoev.ru                              return 0;
880Sigor@sysoev.ru                          }"
890Sigor@sysoev.ru    else
900Sigor@sysoev.ru        nxt_feature_test="int main() {
910Sigor@sysoev.ru                              int  n = 0;
920Sigor@sysoev.ru                              int  o = 0;
930Sigor@sysoev.ru
940Sigor@sysoev.ru                              if (!__compare_and_swap(&n, &o, 3))
950Sigor@sysoev.ru                                  return 1;
960Sigor@sysoev.ru                              if (__fetch_and_add(&n, 1) != 3)
970Sigor@sysoev.ru                                  return 1;
980Sigor@sysoev.ru                              if (__fetch_and_swap(&n, 5) != 4)
990Sigor@sysoev.ru                                  return 1;
1000Sigor@sysoev.ru                              if (n != 5)
1010Sigor@sysoev.ru                                  return 1;
1020Sigor@sysoev.ru                              __isync();
1030Sigor@sysoev.ru                              __lwsync();
1040Sigor@sysoev.ru                              return 0;
1050Sigor@sysoev.ru                          }"
1060Sigor@sysoev.ru    fi
1070Sigor@sysoev.ru
1080Sigor@sysoev.ru    nxt_feature="xlC builtin atomic operations"
1090Sigor@sysoev.ru    nxt_feature_name=NXT_HAVE_XLC_ATOMIC
1100Sigor@sysoev.ru    nxt_feature_run=yes
1110Sigor@sysoev.ru    nxt_feature_incs=
1120Sigor@sysoev.ru    nxt_feature_libs=
1130Sigor@sysoev.ru    . auto/feature
1140Sigor@sysoev.rufi
1150Sigor@sysoev.ru
1160Sigor@sysoev.ru
1170Sigor@sysoev.ruif [ $nxt_found = no ]; then
1180Sigor@sysoev.ru    $echo
1190Sigor@sysoev.ru    $echo $0: error: no atomic operations found.
1200Sigor@sysoev.ru    $echo
1210Sigor@sysoev.ru    exit 1;
1220Sigor@sysoev.rufi
123