atomic_count_sync.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
  3. //
  4. // boost/detail/atomic_count_sync.hpp
  5. //
  6. // atomic_count for g++ 4.1+
  7. //
  8. // http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
  9. //
  10. // Copyright 2007 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. #if defined( __ia64__ ) && defined( __INTEL_COMPILER )
  17. # include <ia64intrin.h>
  18. #endif
  19. namespace boost
  20. {
  21. namespace detail
  22. {
  23. class atomic_count
  24. {
  25. public:
  26. explicit atomic_count( long v ) : value_( v ) {}
  27. long operator++()
  28. {
  29. return __sync_add_and_fetch( &value_, 1 );
  30. }
  31. long operator--()
  32. {
  33. return __sync_add_and_fetch( &value_, -1 );
  34. }
  35. operator long() const
  36. {
  37. return __sync_fetch_and_add( &value_, 0 );
  38. }
  39. private:
  40. atomic_count(atomic_count const &);
  41. atomic_count & operator=(atomic_count const &);
  42. mutable long value_;
  43. };
  44. } // namespace detail
  45. } // namespace boost
  46. #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED