diff --git a/asio/include/asio/detail/impl/resolver_service_base.ipp b/asio/include/asio/detail/impl/resolver_service_base.ipp index e9e94c4e..e05f260e 100644 --- a/asio/include/asio/detail/impl/resolver_service_base.ipp +++ b/asio/include/asio/detail/impl/resolver_service_base.ipp @@ -52,10 +52,10 @@ resolver_service_base::~resolver_service_base() void resolver_service_base::shutdown_service() { work_.reset(); - if (work_io_service_) + if (work_io_service_.get()) { work_io_service_->stop(); - if (work_thread_) + if (work_thread_.get()) { work_thread_->join(); work_thread_.reset(); @@ -67,7 +67,7 @@ void resolver_service_base::shutdown_service() void resolver_service_base::fork_service( asio::io_service::fork_event event) { - if (work_thread_) + if (work_thread_.get()) { if (event == asio::io_service::fork_prepare) { @@ -115,7 +115,7 @@ void resolver_service_base::start_resolve_op(operation* op) void resolver_service_base::start_work_thread() { asio::detail::mutex::scoped_lock lock(mutex_); - if (!work_thread_) + if (!work_thread_.get()) { work_thread_.reset(new asio::detail::thread( work_io_service_runner(*work_io_service_))); diff --git a/asio/include/asio/detail/impl/strand_service.ipp b/asio/include/asio/detail/impl/strand_service.ipp index 84b806a5..3cb644b8 100644 --- a/asio/include/asio/detail/impl/strand_service.ipp +++ b/asio/include/asio/detail/impl/strand_service.ipp @@ -69,7 +69,7 @@ void strand_service::construct(strand_service::implementation_type& impl) asio::detail::mutex::scoped_lock lock(mutex_); - if (!implementations_[index]) + if (!implementations_[index].get()) implementations_[index].reset(new strand_impl); impl = implementations_[index].get(); } diff --git a/asio/include/asio/detail/impl/win_iocp_io_service.ipp b/asio/include/asio/detail/impl/win_iocp_io_service.ipp index db996c23..ca3125e5 100644 --- a/asio/include/asio/detail/impl/win_iocp_io_service.ipp +++ b/asio/include/asio/detail/impl/win_iocp_io_service.ipp @@ -89,7 +89,7 @@ void win_iocp_io_service::shutdown_service() { ::InterlockedExchange(&shutdown_, 1); - if (timer_thread_) + if (timer_thread_.get()) { LARGE_INTEGER timeout; timeout.QuadPart = 1; @@ -125,7 +125,7 @@ void win_iocp_io_service::shutdown_service() } } - if (timer_thread_) + if (timer_thread_.get()) timer_thread_->join(); } @@ -455,7 +455,7 @@ void win_iocp_io_service::do_add_timer_queue(timer_queue_base& queue) &timeout, max_timeout_msec, 0, 0, FALSE); } - if (!timer_thread_) + if (!timer_thread_.get()) { timer_thread_function thread_function = { this }; timer_thread_.reset(new thread(thread_function, 65536)); @@ -471,7 +471,7 @@ void win_iocp_io_service::do_remove_timer_queue(timer_queue_base& queue) void win_iocp_io_service::update_timeout() { - if (timer_thread_) + if (timer_thread_.get()) { // There's no point updating the waitable timer if the new timeout period // exceeds the maximum timeout. In that case, we might as well wait for the diff --git a/asio/include/asio/detail/resolver_service_base.hpp b/asio/include/asio/detail/resolver_service_base.hpp index 406f89ef..ab4d2f52 100644 --- a/asio/include/asio/detail/resolver_service_base.hpp +++ b/asio/include/asio/detail/resolver_service_base.hpp @@ -16,7 +16,6 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" -#include #include "asio/error.hpp" #include "asio/io_service.hpp" #include "asio/detail/mutex.hpp" @@ -24,6 +23,7 @@ #include "asio/detail/operation.hpp" #include "asio/detail/socket_ops.hpp" #include "asio/detail/socket_types.hpp" +#include "asio/detail/scoped_ptr.hpp" #include "asio/detail/thread.hpp" #include "asio/detail/push_options.hpp" @@ -102,16 +102,16 @@ private: asio::detail::mutex mutex_; // Private io_service used for performing asynchronous host resolution. - boost::scoped_ptr work_io_service_; + asio::detail::scoped_ptr work_io_service_; // The work io_service implementation used to post completions. io_service_impl& work_io_service_impl_; // Work for the private io_service to perform. - boost::scoped_ptr work_; + asio::detail::scoped_ptr work_; // Thread used for running the work io_service's run loop. - boost::scoped_ptr work_thread_; + asio::detail::scoped_ptr work_thread_; }; } // namespace detail diff --git a/asio/include/asio/detail/scoped_ptr.hpp b/asio/include/asio/detail/scoped_ptr.hpp new file mode 100644 index 00000000..b4ba10b4 --- /dev/null +++ b/asio/include/asio/detail/scoped_ptr.hpp @@ -0,0 +1,75 @@ +// +// detail/scoped_ptr.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_SCOPED_PTR_HPP +#define ASIO_DETAIL_SCOPED_PTR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/detail/config.hpp" + +namespace asio { +namespace detail { + +template +class scoped_ptr +{ +public: + // Constructor. + explicit scoped_ptr(T* p = 0) + : p_(p) + { + } + + // Destructor. + ~scoped_ptr() + { + delete p_; + } + + // Access. + T* get() + { + return p_; + } + + // Access. + T* operator->() + { + return p_; + } + + // Dereference. + T& operator*() + { + return *p_; + } + + // Reset pointer. + void reset(T* p = 0) + { + delete p_; + p_ = p; + } + +private: + // Disallow copying and assignment. + scoped_ptr(const scoped_ptr&); + scoped_ptr& operator=(const scoped_ptr&); + + T* p_; +}; + +} // namespace detail +} // namespace asio + +#endif // ASIO_DETAIL_SCOPED_PTR_HPP diff --git a/asio/include/asio/detail/strand_service.hpp b/asio/include/asio/detail/strand_service.hpp index e40bb00d..b4503215 100644 --- a/asio/include/asio/detail/strand_service.hpp +++ b/asio/include/asio/detail/strand_service.hpp @@ -16,11 +16,11 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" -#include #include "asio/io_service.hpp" #include "asio/detail/mutex.hpp" #include "asio/detail/op_queue.hpp" #include "asio/detail/operation.hpp" +#include "asio/detail/scoped_ptr.hpp" #include "asio/detail/push_options.hpp" @@ -99,8 +99,8 @@ private: // Number of implementations shared between all strand objects. enum { num_implementations = 193 }; - // The head of a linked list of all implementations. - boost::scoped_ptr implementations_[num_implementations]; + // Pool of implementations. + scoped_ptr implementations_[num_implementations]; // Extra value used when hashing to prevent recycled memory locations from // getting the same strand implementation. diff --git a/asio/include/asio/detail/win_iocp_io_service.hpp b/asio/include/asio/detail/win_iocp_io_service.hpp index 3a29395c..a562834a 100644 --- a/asio/include/asio/detail/win_iocp_io_service.hpp +++ b/asio/include/asio/detail/win_iocp_io_service.hpp @@ -20,10 +20,10 @@ #if defined(ASIO_HAS_IOCP) #include -#include #include "asio/io_service.hpp" #include "asio/detail/mutex.hpp" #include "asio/detail/op_queue.hpp" +#include "asio/detail/scoped_ptr.hpp" #include "asio/detail/socket_types.hpp" #include "asio/detail/timer_op.hpp" #include "asio/detail/timer_queue_base.hpp" @@ -240,7 +240,7 @@ private: friend struct timer_thread_function; // Background thread used for processing timeouts. - boost::scoped_ptr timer_thread_; + scoped_ptr timer_thread_; // A waitable timer object used for waiting for timeouts. auto_handle waitable_timer_; diff --git a/asio/include/asio/system_error.hpp b/asio/include/asio/system_error.hpp index dc8cc8d2..5fc7f391 100644 --- a/asio/include/asio/system_error.hpp +++ b/asio/include/asio/system_error.hpp @@ -20,11 +20,11 @@ #if defined(ASIO_HAS_STD_SYSTEM_ERROR) # include #else // defined(ASIO_HAS_STD_SYSTEM_ERROR) -# include # include # include # include # include "asio/error_code.hpp" +# include "asio/detail/scoped_ptr.hpp" #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR) #include "asio/detail/push_options.hpp" @@ -87,7 +87,7 @@ public: try #endif // !defined(BOOST_NO_EXCEPTIONS) { - if (!what_) + if (!what_.get()) { std::string tmp(context_); if (tmp.length()) @@ -119,7 +119,7 @@ private: std::string context_; // The string representation of the error. - mutable boost::scoped_ptr what_; + mutable asio::detail::scoped_ptr what_; }; #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)