atomic_count_win64.hpp 1.6 KB

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