gcc_builtins.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef ATOMIC_GCC_BUILTINS_INCLUDED
  2. #define ATOMIC_GCC_BUILTINS_INCLUDED
  3. /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  14. #define make_atomic_add_body(S) \
  15. v= __sync_fetch_and_add(a, v);
  16. #define make_atomic_fas_body(S) \
  17. v= __sync_lock_test_and_set(a, v);
  18. #define make_atomic_cas_body(S) \
  19. int ## S sav; \
  20. int ## S cmp_val= *cmp; \
  21. sav= __sync_val_compare_and_swap(a, cmp_val, set);\
  22. if (!(ret= (sav == cmp_val))) *cmp= sav
  23. #ifdef MY_ATOMIC_MODE_DUMMY
  24. #define make_atomic_load_body(S) ret= *a
  25. #define make_atomic_store_body(S) *a= v
  26. #define MY_ATOMIC_MODE "gcc-builtins-up"
  27. #elif defined(HAVE_GCC_C11_ATOMICS)
  28. #define MY_ATOMIC_MODE "gcc-atomics-smp"
  29. #define make_atomic_load_body(S) \
  30. ret= __atomic_load_n(a, __ATOMIC_SEQ_CST)
  31. #define make_atomic_store_body(S) \
  32. __atomic_store_n(a, v, __ATOMIC_SEQ_CST)
  33. #else
  34. #define MY_ATOMIC_MODE "gcc-builtins-smp"
  35. #define make_atomic_load_body(S) \
  36. ret= __sync_fetch_and_or(a, 0);
  37. #define make_atomic_store_body(S) \
  38. (void) __sync_lock_test_and_set(a, v);
  39. #endif
  40. #endif /* ATOMIC_GCC_BUILTINS_INCLUDED */