Add ability to specify the level of concurrency desired, which is currently
used by Win32's I/O completion ports.
This commit is contained in:
parent
c9d679e579
commit
fd0246b896
@ -47,6 +47,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void init(size_t concurrency_hint)
|
||||
{
|
||||
}
|
||||
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
void shutdown_service()
|
||||
{
|
||||
|
@ -47,11 +47,17 @@ public:
|
||||
// Constructor.
|
||||
win_iocp_io_service(asio::io_service& io_service)
|
||||
: asio::io_service::service(io_service),
|
||||
iocp_(::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0)),
|
||||
iocp_(),
|
||||
outstanding_work_(0),
|
||||
interrupted_(0),
|
||||
shutdown_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void init(size_t concurrency_hint)
|
||||
{
|
||||
iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0,
|
||||
static_cast<DWORD>((std::min<size_t>)(concurrency_hint, DWORD(~0))));
|
||||
if (!iocp_.handle)
|
||||
{
|
||||
DWORD last_error = ::GetLastError();
|
||||
@ -377,8 +383,8 @@ private:
|
||||
struct iocp_holder
|
||||
{
|
||||
HANDLE handle;
|
||||
iocp_holder(HANDLE h) : handle(h) {}
|
||||
~iocp_holder() { ::CloseHandle(handle); }
|
||||
iocp_holder() : handle(0) {}
|
||||
~iocp_holder() { if (handle) ::CloseHandle(handle); }
|
||||
} iocp_;
|
||||
|
||||
// The count of unfinished work.
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <limits>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/detail/epoll_reactor.hpp"
|
||||
#include "asio/detail/kqueue_reactor.hpp"
|
||||
#include "asio/detail/select_reactor.hpp"
|
||||
@ -29,6 +33,14 @@ inline io_service::io_service()
|
||||
: service_registry_(*this),
|
||||
impl_(service_registry_.use_service<impl_type>())
|
||||
{
|
||||
impl_.init((std::numeric_limits<size_t>::max)());
|
||||
}
|
||||
|
||||
inline io_service::io_service(size_t concurrency_hint)
|
||||
: service_registry_(*this),
|
||||
impl_(service_registry_.use_service<impl_type>())
|
||||
{
|
||||
impl_.init(concurrency_hint);
|
||||
}
|
||||
|
||||
inline size_t io_service::run()
|
||||
|
@ -87,6 +87,13 @@ public:
|
||||
/// Default constructor.
|
||||
io_service();
|
||||
|
||||
/// Construct with a hint about the required level of concurrency.
|
||||
/**
|
||||
* @param concurrency_hint A suggestion to the implementation on how many
|
||||
* threads it should allow to run simultaneously.
|
||||
*/
|
||||
explicit io_service(size_t concurrency_hint);
|
||||
|
||||
/// Run the io_service's event processing loop.
|
||||
/**
|
||||
* The run() function blocks until all work has finished and there are no
|
||||
|
Loading…
Reference in New Issue
Block a user