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