From 81f7fbd8f6f3c89f4f99ba80ef5811cb0e232502 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sat, 23 May 2015 10:56:34 +1000 Subject: [PATCH] Change type of concurrency_hint to int. --- asio/include/asio/detail/impl/scheduler.ipp | 2 +- .../asio/detail/impl/win_iocp_io_context.ipp | 5 ++--- asio/include/asio/detail/scheduler.hpp | 2 +- asio/include/asio/detail/win_iocp_io_context.hpp | 2 +- asio/include/asio/impl/io_context.ipp | 15 +++++++-------- asio/include/asio/io_context.hpp | 6 +++--- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/asio/include/asio/detail/impl/scheduler.ipp b/asio/include/asio/detail/impl/scheduler.ipp index 6bc9cf0f..91d57947 100644 --- a/asio/include/asio/detail/impl/scheduler.ipp +++ b/asio/include/asio/detail/impl/scheduler.ipp @@ -84,7 +84,7 @@ struct scheduler::work_cleanup }; scheduler::scheduler( - asio::execution_context& ctx, std::size_t concurrency_hint) + asio::execution_context& ctx, int concurrency_hint) : asio::detail::execution_context_service_base(ctx), one_thread_(concurrency_hint == 1), mutex_(), diff --git a/asio/include/asio/detail/impl/win_iocp_io_context.ipp b/asio/include/asio/detail/impl/win_iocp_io_context.ipp index bf5a20f5..3bc1a8d8 100644 --- a/asio/include/asio/detail/impl/win_iocp_io_context.ipp +++ b/asio/include/asio/detail/impl/win_iocp_io_context.ipp @@ -62,7 +62,7 @@ struct win_iocp_io_context::timer_thread_function }; win_iocp_io_context::win_iocp_io_context( - asio::execution_context& ctx, size_t concurrency_hint) + asio::execution_context& ctx, int concurrency_hint) : execution_context_service_base(ctx), iocp_(), outstanding_work_(0), @@ -75,8 +75,7 @@ win_iocp_io_context::win_iocp_io_context( ASIO_HANDLER_TRACKING_INIT; iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, - static_cast(concurrency_hint < DWORD(~0) - ? concurrency_hint : DWORD(~0))); + static_cast(concurrency_hint >= 0 ? concurrency_hint : DWORD(~0))); if (!iocp_.handle) { DWORD last_error = ::GetLastError(); diff --git a/asio/include/asio/detail/scheduler.hpp b/asio/include/asio/detail/scheduler.hpp index 6bdcfbb4..fb86f530 100644 --- a/asio/include/asio/detail/scheduler.hpp +++ b/asio/include/asio/detail/scheduler.hpp @@ -44,7 +44,7 @@ public: // Constructor. Specifies the number of concurrent threads that are likely to // run the scheduler. If set to 1 certain optimisation are performed. ASIO_DECL scheduler(asio::execution_context& ctx, - std::size_t concurrency_hint = 0); + int concurrency_hint = 0); // Destroy all user-defined handler objects owned by the service. ASIO_DECL void shutdown(); diff --git a/asio/include/asio/detail/win_iocp_io_context.hpp b/asio/include/asio/detail/win_iocp_io_context.hpp index ffb8c3b5..e6a25c4f 100644 --- a/asio/include/asio/detail/win_iocp_io_context.hpp +++ b/asio/include/asio/detail/win_iocp_io_context.hpp @@ -48,7 +48,7 @@ public: // Constructor. Specifies a concurrency hint that is passed through to the // underlying I/O completion port. ASIO_DECL win_iocp_io_context(asio::execution_context& ctx, - size_t concurrency_hint = 0); + int concurrency_hint = -1); // Destroy all user-defined handler objects owned by the service. ASIO_DECL void shutdown(); diff --git a/asio/include/asio/impl/io_context.ipp b/asio/include/asio/impl/io_context.ipp index 2cce94bc..a1d5959d 100644 --- a/asio/include/asio/impl/io_context.ipp +++ b/asio/include/asio/impl/io_context.ipp @@ -33,21 +33,20 @@ namespace asio { io_context::io_context() - : impl_(create_impl()) + : impl_(add_impl(new impl_type(*this))) { } -io_context::io_context(std::size_t concurrency_hint) - : impl_(create_impl(concurrency_hint)) +io_context::io_context(int concurrency_hint) + : impl_(add_impl(new impl_type(*this, concurrency_hint))) { } -io_context::impl_type& io_context::create_impl(std::size_t concurrency_hint) +io_context::impl_type& io_context::add_impl(io_context::impl_type* impl) { - asio::detail::scoped_ptr impl( - new impl_type(*this, concurrency_hint)); - asio::add_service(*this, impl.get()); - return *impl.release(); + asio::detail::scoped_ptr scoped_impl(impl); + asio::add_service(*this, scoped_impl.get()); + return *scoped_impl.release(); } io_context::~io_context() diff --git a/asio/include/asio/io_context.hpp b/asio/include/asio/io_context.hpp index 2f92a6dc..7fb49a9e 100644 --- a/asio/include/asio/io_context.hpp +++ b/asio/include/asio/io_context.hpp @@ -170,7 +170,7 @@ public: * @param concurrency_hint A suggestion to the implementation on how many * threads it should allow to run simultaneously. */ - ASIO_DECL explicit io_context(std::size_t concurrency_hint); + ASIO_DECL explicit io_context(int concurrency_hint); /// Destructor. /** @@ -479,8 +479,8 @@ public: #endif // !defined(ASIO_NO_DEPRECATED) private: - // Helper function to create the implementation. - ASIO_DECL impl_type& create_impl(std::size_t concurrency_hint = 0); + // Helper function to add the implementation. + ASIO_DECL impl_type& add_impl(impl_type* impl); // Backwards compatible overload for use with services derived from // io_context::service.