atomic_count_win32.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. namespace boost
  18. {
  19. namespace detail
  20. {
  21. class atomic_count
  22. {
  23. public:
  24. explicit atomic_count( long v ): value_( v )
  25. {
  26. }
  27. long operator++()
  28. {
  29. return BOOST_SP_INTERLOCKED_INCREMENT( &value_ );
  30. }
  31. long operator--()
  32. {
  33. return BOOST_SP_INTERLOCKED_DECREMENT( &value_ );
  34. }
  35. operator long() const
  36. {
  37. return static_cast<long const volatile &>( value_ );
  38. }
  39. private:
  40. atomic_count( atomic_count const & );
  41. atomic_count & operator=( atomic_count const & );
  42. long value_;
  43. };
  44. } // namespace detail
  45. } // namespace boost
  46. #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED