solaris.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #ifndef _atomic_h_cleanup_
  13. #define _atomic_h_cleanup_ "atomic/solaris.h"
  14. #include <atomic.h>
  15. #define MY_ATOMIC_MODE "solaris-atomic"
  16. #if defined(__GNUC__)
  17. #define atomic_typeof(T,V) __typeof__(V)
  18. #else
  19. #define atomic_typeof(T,V) T
  20. #endif
  21. #define uintptr_t void *
  22. #define atomic_or_ptr_nv(X,Y) (void *)atomic_or_ulong_nv((volatile ulong_t *)X, Y)
  23. #define make_atomic_cas_body(S) \
  24. atomic_typeof(uint ## S ## _t, *cmp) sav; \
  25. sav = atomic_cas_ ## S( \
  26. (volatile uint ## S ## _t *)a, \
  27. (uint ## S ## _t)*cmp, \
  28. (uint ## S ## _t)set); \
  29. if (! (ret= (sav == *cmp))) \
  30. *cmp= sav;
  31. #define make_atomic_add_body(S) \
  32. int ## S nv; /* new value */ \
  33. nv= atomic_add_ ## S ## _nv((volatile uint ## S ## _t *)a, v); \
  34. v= nv - v
  35. /* ------------------------------------------------------------------------ */
  36. #ifdef MY_ATOMIC_MODE_DUMMY
  37. #define make_atomic_load_body(S) ret= *a
  38. #define make_atomic_store_body(S) *a= v
  39. #else /* MY_ATOMIC_MODE_DUMMY */
  40. #define make_atomic_load_body(S) \
  41. ret= atomic_or_ ## S ## _nv((volatile uint ## S ## _t *)a, 0)
  42. #define make_atomic_store_body(S) \
  43. (void) atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
  44. #endif
  45. #define make_atomic_fas_body(S) \
  46. v= atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
  47. #else /* cleanup */
  48. #undef uintptr_t
  49. #undef atomic_or_ptr_nv
  50. #endif