Change type of concurrency_hint to int.

This commit is contained in:
Christopher Kohlhoff 2015-05-23 10:56:34 +10:00
parent 5f9639bc1b
commit 81f7fbd8f6
6 changed files with 15 additions and 17 deletions

View File

@ -84,7 +84,7 @@ struct scheduler::work_cleanup
}; };
scheduler::scheduler( scheduler::scheduler(
asio::execution_context& ctx, std::size_t concurrency_hint) asio::execution_context& ctx, int concurrency_hint)
: asio::detail::execution_context_service_base<scheduler>(ctx), : asio::detail::execution_context_service_base<scheduler>(ctx),
one_thread_(concurrency_hint == 1), one_thread_(concurrency_hint == 1),
mutex_(), mutex_(),

View File

@ -62,7 +62,7 @@ struct win_iocp_io_context::timer_thread_function
}; };
win_iocp_io_context::win_iocp_io_context( 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<win_iocp_io_context>(ctx), : execution_context_service_base<win_iocp_io_context>(ctx),
iocp_(), iocp_(),
outstanding_work_(0), outstanding_work_(0),
@ -75,8 +75,7 @@ win_iocp_io_context::win_iocp_io_context(
ASIO_HANDLER_TRACKING_INIT; ASIO_HANDLER_TRACKING_INIT;
iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0,
static_cast<DWORD>(concurrency_hint < DWORD(~0) static_cast<DWORD>(concurrency_hint >= 0 ? concurrency_hint : DWORD(~0)));
? concurrency_hint : DWORD(~0)));
if (!iocp_.handle) if (!iocp_.handle)
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();

View File

@ -44,7 +44,7 @@ public:
// Constructor. Specifies the number of concurrent threads that are likely to // Constructor. Specifies the number of concurrent threads that are likely to
// run the scheduler. If set to 1 certain optimisation are performed. // run the scheduler. If set to 1 certain optimisation are performed.
ASIO_DECL scheduler(asio::execution_context& ctx, 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. // Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown(); ASIO_DECL void shutdown();

View File

@ -48,7 +48,7 @@ public:
// Constructor. Specifies a concurrency hint that is passed through to the // Constructor. Specifies a concurrency hint that is passed through to the
// underlying I/O completion port. // underlying I/O completion port.
ASIO_DECL win_iocp_io_context(asio::execution_context& ctx, 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. // Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown(); ASIO_DECL void shutdown();

View File

@ -33,21 +33,20 @@
namespace asio { namespace asio {
io_context::io_context() io_context::io_context()
: impl_(create_impl()) : impl_(add_impl(new impl_type(*this)))
{ {
} }
io_context::io_context(std::size_t concurrency_hint) io_context::io_context(int concurrency_hint)
: impl_(create_impl(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_type> impl( asio::detail::scoped_ptr<impl_type> scoped_impl(impl);
new impl_type(*this, concurrency_hint)); asio::add_service<impl_type>(*this, scoped_impl.get());
asio::add_service<impl_type>(*this, impl.get()); return *scoped_impl.release();
return *impl.release();
} }
io_context::~io_context() io_context::~io_context()

View File

@ -170,7 +170,7 @@ public:
* @param concurrency_hint A suggestion to the implementation on how many * @param concurrency_hint A suggestion to the implementation on how many
* threads it should allow to run simultaneously. * 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. /// Destructor.
/** /**
@ -479,8 +479,8 @@ public:
#endif // !defined(ASIO_NO_DEPRECATED) #endif // !defined(ASIO_NO_DEPRECATED)
private: private:
// Helper function to create the implementation. // Helper function to add the implementation.
ASIO_DECL impl_type& create_impl(std::size_t concurrency_hint = 0); ASIO_DECL impl_type& add_impl(impl_type* impl);
// Backwards compatible overload for use with services derived from // Backwards compatible overload for use with services derived from
// io_context::service. // io_context::service.