atomic_count.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. //
  8. // boost/detail/atomic_count.hpp - thread/SMP safe reference counter
  9. //
  10. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
  11. // Copyright (c) 2013 Peter Dimov
  12. //
  13. // Distributed under the Boost Software License, Version 1.0.
  14. // See accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt
  16. //
  17. // typedef <implementation-defined> boost::detail::atomic_count;
  18. //
  19. // atomic_count a(n);
  20. //
  21. // (n is convertible to long)
  22. //
  23. // Effects: Constructs an atomic_count with an initial value of n
  24. //
  25. // a;
  26. //
  27. // Returns: (long) the current value of a
  28. // Memory Ordering: acquire
  29. //
  30. // ++a;
  31. //
  32. // Effects: Atomically increments the value of a
  33. // Returns: (long) the new value of a
  34. // Memory Ordering: acquire/release
  35. //
  36. // --a;
  37. //
  38. // Effects: Atomically decrements the value of a
  39. // Returns: (long) the new value of a
  40. // Memory Ordering: acquire/release
  41. //
  42. #include <boost/smart_ptr/detail/sp_has_gcc_intrinsics.hpp>
  43. #include <boost/smart_ptr/detail/sp_has_sync_intrinsics.hpp>
  44. #include <boost/config.hpp>
  45. #if defined( BOOST_AC_DISABLE_THREADS )
  46. # include <boost/smart_ptr/detail/atomic_count_nt.hpp>
  47. #elif defined( BOOST_AC_USE_STD_ATOMIC )
  48. # include <boost/smart_ptr/detail/atomic_count_std_atomic.hpp>
  49. #elif defined( BOOST_AC_USE_SPINLOCK )
  50. # include <boost/smart_ptr/detail/atomic_count_spin.hpp>
  51. #elif defined( BOOST_AC_USE_PTHREADS )
  52. # include <boost/smart_ptr/detail/atomic_count_pt.hpp>
  53. #elif defined( BOOST_SP_DISABLE_THREADS )
  54. # include <boost/smart_ptr/detail/atomic_count_nt.hpp>
  55. #elif defined( BOOST_SP_USE_STD_ATOMIC )
  56. # include <boost/smart_ptr/detail/atomic_count_std_atomic.hpp>
  57. #elif defined( BOOST_SP_USE_SPINLOCK )
  58. # include <boost/smart_ptr/detail/atomic_count_spin.hpp>
  59. #elif defined( BOOST_SP_USE_PTHREADS )
  60. # include <boost/smart_ptr/detail/atomic_count_pt.hpp>
  61. #elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
  62. # include <boost/smart_ptr/detail/atomic_count_nt.hpp>
  63. #elif defined( BOOST_SP_HAS_GCC_INTRINSICS )
  64. # include <boost/smart_ptr/detail/atomic_count_gcc_atomic.hpp>
  65. #elif !defined( BOOST_NO_CXX11_HDR_ATOMIC )
  66. # include <boost/smart_ptr/detail/atomic_count_std_atomic.hpp>
  67. #elif defined( BOOST_SP_HAS_SYNC_INTRINSICS )
  68. # include <boost/smart_ptr/detail/atomic_count_sync.hpp>
  69. #elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) && !defined( __PATHSCALE__ )
  70. # include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>
  71. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
  72. # include <boost/smart_ptr/detail/atomic_count_win32.hpp>
  73. #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
  74. # include <boost/smart_ptr/detail/atomic_count_gcc.hpp>
  75. #elif !defined( BOOST_HAS_THREADS )
  76. # include <boost/smart_ptr/detail/atomic_count_nt.hpp>
  77. #else
  78. # include <boost/smart_ptr/detail/atomic_count_spin.hpp>
  79. #endif
  80. #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED