atomic-machine.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (C) 2003-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _ATOMIC_MACHINE_H
  15. #define _ATOMIC_MACHINE_H 1
  16. #include <stdint.h>
  17. /* Coldfire has no atomic compare-and-exchange operation, and the
  18. kernel provides no userspace atomicity operations. Here we just
  19. use generic non-atomic implementations instead. */
  20. typedef int8_t atomic8_t;
  21. typedef uint8_t uatomic8_t;
  22. typedef int_fast8_t atomic_fast8_t;
  23. typedef uint_fast8_t uatomic_fast8_t;
  24. typedef int16_t atomic16_t;
  25. typedef uint16_t uatomic16_t;
  26. typedef int_fast16_t atomic_fast16_t;
  27. typedef uint_fast16_t uatomic_fast16_t;
  28. typedef int32_t atomic32_t;
  29. typedef uint32_t uatomic32_t;
  30. typedef int_fast32_t atomic_fast32_t;
  31. typedef uint_fast32_t uatomic_fast32_t;
  32. typedef int64_t atomic64_t;
  33. typedef uint64_t uatomic64_t;
  34. typedef int_fast64_t atomic_fast64_t;
  35. typedef uint_fast64_t uatomic_fast64_t;
  36. typedef intptr_t atomicptr_t;
  37. typedef uintptr_t uatomicptr_t;
  38. typedef intmax_t atomic_max_t;
  39. typedef uintmax_t uatomic_max_t;
  40. /* If we have just non-atomic operations, we can as well make them wide. */
  41. #define __HAVE_64B_ATOMICS 1
  42. #define USE_ATOMIC_COMPILER_BUILTINS 0
  43. /* XXX Is this actually correct? */
  44. #define ATOMIC_EXCHANGE_USES_CAS 1
  45. /* The only basic operation needed is compare and exchange. */
  46. #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
  47. ({ __typeof (mem) __gmemp = (mem); \
  48. __typeof (*mem) __gret = *__gmemp; \
  49. __typeof (*mem) __gnewval = (newval); \
  50. \
  51. if (__gret == (oldval)) \
  52. *__gmemp = __gnewval; \
  53. __gret; })
  54. #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
  55. ({ __typeof (mem) __gmemp = (mem); \
  56. __typeof (*mem) __gnewval = (newval); \
  57. \
  58. *__gmemp == (oldval) ? (*__gmemp = __gnewval, 0) : 1; })
  59. #endif