]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_win32.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / detail / atomic_count_win32.hpp
1 #ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
2 #define BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 //  boost/detail/atomic_count_win32.hpp
12 //
13 //  Copyright (c) 2001, 2002, 2003 Peter Dimov
14 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19
20 #ifdef BOOST_USE_WINDOWS_H
21 #  include <windows.h>
22 #endif
23
24 namespace boost
25 {
26
27 namespace detail
28 {
29
30 #ifndef BOOST_USE_WINDOWS_H
31
32 #ifdef _WIN64
33
34 // Intel 6.0 on Win64 version, posted by Tim Fenders to [boost-users]
35
36 extern "C" long_type __cdecl _InterlockedIncrement(long volatile *);
37 extern "C" long_type __cdecl _InterlockedDecrement(long volatile *);
38
39 #pragma intrinsic(_InterlockedIncrement)
40 #pragma intrinsic(_InterlockedDecrement)
41
42 inline long InterlockedIncrement(long volatile * lp)
43
44     return _InterlockedIncrement(lp);
45 }
46
47 inline long InterlockedDecrement(long volatile* lp)
48
49     return _InterlockedDecrement(lp);
50 }
51
52 #else  // _WIN64
53
54 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile *);
55 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile *);
56
57 #endif // _WIN64
58
59 #endif // #ifndef BOOST_USE_WINDOWS_H
60
61 class atomic_count
62 {
63 public:
64
65     explicit atomic_count(long v): value_(v)
66     {
67     }
68
69     long operator++()
70     {
71         // Some older <windows.h> versions do not accept volatile
72         return InterlockedIncrement(const_cast<long*>(&value_));
73     }
74
75     long operator--()
76     {
77         return InterlockedDecrement(const_cast<long*>(&value_));
78     }
79
80     operator long() const
81     {
82         return value_;
83     }
84
85 private:
86
87     atomic_count(atomic_count const &);
88     atomic_count & operator=(atomic_count const &);
89
90     volatile long value_;
91 };
92
93 } // namespace detail
94
95 } // namespace boost
96
97 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED