2002-01-22 13:38:52 +00:00
|
|
|
#ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
|
|
|
|
#define BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
|
|
|
|
|
2003-11-28 15:35:21 +00:00
|
|
|
// MS compatible compilers support #pragma once
|
|
|
|
|
2003-06-12 17:09:24 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
|
|
|
# pragma once
|
2002-01-22 13:38:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// boost/detail/atomic_count_win32.hpp
|
|
|
|
//
|
2003-02-08 16:05:46 +00:00
|
|
|
// Copyright (c) 2001, 2002, 2003 Peter Dimov
|
2002-01-22 13:38:52 +00:00
|
|
|
//
|
|
|
|
// Permission to copy, use, modify, sell and distribute this software
|
|
|
|
// is granted provided this copyright notice appears in all copies.
|
|
|
|
// This software is provided "as is" without express or implied
|
|
|
|
// warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
//
|
|
|
|
|
2003-02-08 16:05:46 +00:00
|
|
|
#ifdef BOOST_USE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
2002-03-15 22:00:10 +00:00
|
|
|
|
2002-01-22 13:38:52 +00:00
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
2003-02-08 16:05:46 +00:00
|
|
|
#ifndef BOOST_USE_WINDOWS_H
|
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
|
|
|
|
// Intel 6.0 on Win64 version, posted by Tim Fenders to [boost-users]
|
|
|
|
|
|
|
|
extern "C" long_type __cdecl _InterlockedIncrement(long volatile *);
|
|
|
|
extern "C" long_type __cdecl _InterlockedDecrement(long volatile *);
|
|
|
|
|
|
|
|
#pragma intrinsic(_InterlockedIncrement)
|
|
|
|
#pragma intrinsic(_InterlockedDecrement)
|
|
|
|
|
|
|
|
inline long InterlockedIncrement(long volatile * lp)
|
|
|
|
{
|
|
|
|
return _InterlockedIncrement(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline long InterlockedDecrement(long volatile* lp)
|
|
|
|
{
|
|
|
|
return _InterlockedDecrement(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // _WIN64
|
|
|
|
|
|
|
|
extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile *);
|
|
|
|
extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile *);
|
|
|
|
|
|
|
|
#endif // _WIN64
|
|
|
|
|
|
|
|
#endif // #ifndef BOOST_USE_WINDOWS_H
|
|
|
|
|
2002-01-22 13:38:52 +00:00
|
|
|
class atomic_count
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit atomic_count(long v): value_(v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
long operator++()
|
|
|
|
{
|
2003-02-08 16:05:46 +00:00
|
|
|
// Some older <windows.h> versions do not accept volatile
|
|
|
|
return InterlockedIncrement(const_cast<long*>(&value_));
|
2002-01-22 13:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long operator--()
|
|
|
|
{
|
2003-02-08 16:05:46 +00:00
|
|
|
return InterlockedDecrement(const_cast<long*>(&value_));
|
2002-01-22 13:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
operator long() const
|
|
|
|
{
|
|
|
|
return value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
atomic_count(atomic_count const &);
|
|
|
|
atomic_count & operator=(atomic_count const &);
|
|
|
|
|
|
|
|
volatile long value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
#endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
|