atomic_count_win32.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef DAHUA_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
  2. #define DAHUA_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. #if defined(_MSC_VER) && (_MSC_VER >= 1300) && (_MSC_VER < 1800)
  17. extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * );
  18. extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * );
  19. #else
  20. #define WIN32_LEAN_AND_MEAN
  21. # include <windows.h>
  22. #endif
  23. namespace Dahua {
  24. namespace Infra {
  25. namespace Detail {
  26. class atomic_count
  27. {
  28. public:
  29. explicit atomic_count( long v ): value_( v )
  30. {
  31. }
  32. long operator++()
  33. {
  34. return InterlockedIncrement( &value_ );
  35. }
  36. long operator--()
  37. {
  38. return InterlockedDecrement( &value_ );
  39. }
  40. operator long() const
  41. {
  42. return static_cast<long const volatile &>( value_ );
  43. }
  44. long get() const
  45. {
  46. return static_cast<long const volatile &>(value_);
  47. }
  48. void set(long v)
  49. {
  50. value_ = v;
  51. return;
  52. }
  53. private:
  54. atomic_count( atomic_count const & );
  55. atomic_count & operator=( atomic_count const & );
  56. long value_;
  57. };
  58. } // namespace Detail
  59. } // namespace Infra
  60. } // namespace Dahua
  61. #endif // #ifndef DAHUA_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED