atomic_count_win32.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_WIN32_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_win32.hpp
  9. //
  10. // Copyright (c) 2001-2005 Peter Dimov
  11. //
  12. // Distributed under the Boost Software License, Version 1.0. (See
  13. // accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. //
  16. #include <boost/smart_ptr/detail/sp_interlocked.hpp>
  17. #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
  18. #include <boost/config/pragma_message.hpp>
  19. BOOST_PRAGMA_MESSAGE("Using Win32 atomic_count")
  20. #endif
  21. namespace boost
  22. {
  23. namespace detail
  24. {
  25. class atomic_count
  26. {
  27. public:
  28. explicit atomic_count( long v ): value_( v )
  29. {
  30. }
  31. long operator++()
  32. {
  33. return BOOST_SP_INTERLOCKED_INCREMENT( &value_ );
  34. }
  35. long operator--()
  36. {
  37. return BOOST_SP_INTERLOCKED_DECREMENT( &value_ );
  38. }
  39. operator long() const
  40. {
  41. return static_cast<long const volatile &>( value_ );
  42. }
  43. private:
  44. atomic_count( atomic_count const & );
  45. atomic_count & operator=( atomic_count const & );
  46. long value_;
  47. };
  48. } // namespace detail
  49. } // namespace boost
  50. #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED