]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_win32.hpp
Boost 1.31.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 //  Permission to copy, use, modify, sell and distribute this software
16 //  is granted provided this copyright notice appears in all copies.
17 //  This software is provided "as is" without express or implied
18 //  warranty, and with no claim as to its suitability for any purpose.
19 //
20
21 #ifdef BOOST_USE_WINDOWS_H
22 #  include <windows.h>
23 #endif
24
25 namespace boost
26 {
27
28 namespace detail
29 {
30
31 #ifndef BOOST_USE_WINDOWS_H
32
33 #ifdef _WIN64
34
35 // Intel 6.0 on Win64 version, posted by Tim Fenders to [boost-users]
36
37 extern "C" long_type __cdecl _InterlockedIncrement(long volatile *);
38 extern "C" long_type __cdecl _InterlockedDecrement(long volatile *);
39
40 #pragma intrinsic(_InterlockedIncrement)
41 #pragma intrinsic(_InterlockedDecrement)
42
43 inline long InterlockedIncrement(long volatile * lp)
44
45     return _InterlockedIncrement(lp);
46 }
47
48 inline long InterlockedDecrement(long volatile* lp)
49
50     return _InterlockedDecrement(lp);
51 }
52
53 #else  // _WIN64
54
55 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile *);
56 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile *);
57
58 #endif // _WIN64
59
60 #endif // #ifndef BOOST_USE_WINDOWS_H
61
62 class atomic_count
63 {
64 public:
65
66     explicit atomic_count(long v): value_(v)
67     {
68     }
69
70     long operator++()
71     {
72         // Some older <windows.h> versions do not accept volatile
73         return InterlockedIncrement(const_cast<long*>(&value_));
74     }
75
76     long operator--()
77     {
78         return InterlockedDecrement(const_cast<long*>(&value_));
79     }
80
81     operator long() const
82     {
83         return value_;
84     }
85
86 private:
87
88     atomic_count(atomic_count const &);
89     atomic_count & operator=(atomic_count const &);
90
91     volatile long value_;
92 };
93
94 } // namespace detail
95
96 } // namespace boost
97
98 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED