Use std::atomic<> when available.

This commit is contained in:
Christopher Kohlhoff 2011-03-18 15:52:42 +11:00
parent 957ccd6177
commit 0eda7606ae
3 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,38 @@
//
// detail/atomic_count.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_ATOMIC_COUNT_HPP
#define ASIO_DETAIL_ATOMIC_COUNT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_STD_ATOMIC)
# include <atomic>
#else // defined(ASIO_HAS_STD_ATOMIC)
# include <boost/detail/atomic_count.hpp>
#endif // defined(ASIO_HAS_STD_ATOMIC)
namespace asio {
namespace detail {
#if defined(ASIO_HAS_STD_ATOMIC)
typedef std::atomic<long> atomic_count;
#else // defined(ASIO_HAS_STD_ATOMIC)
typedef boost::detail::atomic_count atomic_count;
#endif // defined(ASIO_HAS_STD_ATOMIC)
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_ATOMIC_COUNT_HPP

View File

@ -112,6 +112,17 @@
# endif // defined(BOOST_MSVC)
#endif // !defined(ASIO_DISABLE_STD_SHARED_PTR)
// Standard library support for atomic operations.
#if !defined(ASIO_DISABLE_STD_ATOMIC)
# if defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
# define ASIO_HAS_STD_ATOMIC
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
# endif // defined(__GNUC__)
#endif // !defined(ASIO_DISABLE_STD_ATOMIC)
// Windows: target OS version.
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
# if !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)

View File

@ -19,9 +19,9 @@
#if !defined(ASIO_HAS_IOCP)
#include <boost/detail/atomic_count.hpp>
#include "asio/error_code.hpp"
#include "asio/io_service.hpp"
#include "asio/detail/atomic_count.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/reactor_fwd.hpp"
@ -149,7 +149,7 @@ private:
bool task_interrupted_;
// The count of unfinished work.
boost::detail::atomic_count outstanding_work_;
atomic_count outstanding_work_;
// The queue of handlers that are ready to be delivered.
op_queue<operation> op_queue_;