emul_cas.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. /*
  23. * Ensure, if at all possible, that AO_compare_and_swap_full() is
  24. * available. The emulation should be brute-force signal-safe, even
  25. * though it actually blocks.
  26. * Including this file will generate an error if AO_compare_and_swap_full()
  27. * cannot be made available.
  28. * This will be included from platform-specific atomic_ops files
  29. * if appropriate, and if AO_REQUIRE_CAS is defined. It should not be
  30. * included directly, especially since it affects the implementation
  31. * of other atomic update primitives.
  32. * The implementation assumes that only AO_store_XXX and AO_test_and_set_XXX
  33. * variants are defined, and that AO_test_and_set_XXX is not used to
  34. * operate on compare_and_swap locations.
  35. */
  36. #ifndef AO_ATOMIC_OPS_H
  37. # error This file should not be included directly.
  38. #endif
  39. #ifndef AO_HAVE_double_t
  40. # include "standard_ao_double_t.h"
  41. #endif
  42. AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val,
  43. AO_t new_val);
  44. int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr,
  45. AO_t old_val1, AO_t old_val2,
  46. AO_t new_val1, AO_t new_val2);
  47. void AO_store_full_emulation(volatile AO_t *addr, AO_t val);
  48. #ifndef AO_HAVE_fetch_compare_and_swap_full
  49. # define AO_fetch_compare_and_swap_full(addr, old, newval) \
  50. AO_fetch_compare_and_swap_emulation(addr, old, newval)
  51. # define AO_HAVE_fetch_compare_and_swap_full
  52. #endif
  53. #ifndef AO_HAVE_compare_double_and_swap_double_full
  54. # define AO_compare_double_and_swap_double_full(addr, old1, old2, \
  55. newval1, newval2) \
  56. AO_compare_double_and_swap_double_emulation(addr, old1, old2, \
  57. newval1, newval2)
  58. # define AO_HAVE_compare_double_and_swap_double_full
  59. #endif
  60. #undef AO_store
  61. #undef AO_HAVE_store
  62. #undef AO_store_write
  63. #undef AO_HAVE_store_write
  64. #undef AO_store_release
  65. #undef AO_HAVE_store_release
  66. #undef AO_store_full
  67. #undef AO_HAVE_store_full
  68. #define AO_store_full(addr, val) AO_store_full_emulation(addr, val)
  69. #define AO_HAVE_store_full