Use separate concurrency locking hint for reactor I/O vs registration.

This commit is contained in:
Christopher Kohlhoff 2017-03-12 10:27:07 +11:00
parent ca6aa0cd38
commit 524288cb4f
3 changed files with 16 additions and 8 deletions

View File

@ -26,8 +26,12 @@
// If set, this bit indicates that the scheduler should perform locking.
#define ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER 0x1u
// If set, this bit indicates that the reactor should perform locking.
#define ASIO_CONCURRENCY_HINT_LOCKING_REACTOR 0x2u
// If set, this bit indicates that the reactor should perform locking when
// managing descriptor registrations.
#define ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION 0x2u
// If set, this bit indicates that the reactor should perform locking for I/O.
#define ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO 0x4u
// Helper macro to determine if we have a special concurrency hint.
#define ASIO_CONCURRENCY_HINT_IS_SPECIAL(hint) \
@ -64,13 +68,15 @@
// timers), occur in only one thread at a time.
#define ASIO_CONCURRENCY_HINT_UNSAFE_IO \
static_cast<int>(ASIO_CONCURRENCY_HINT_ID \
| ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER)
| ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
| ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION)
// The special concurrency hint provides full thread safety.
#define ASIO_CONCURRENCY_HINT_SAFE \
static_cast<int>(ASIO_CONCURRENCY_HINT_ID \
| ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
| ASIO_CONCURRENCY_HINT_LOCKING_REACTOR)
| ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION \
| ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO)
// This #define may be overridden at compile time to specify a program-wide
// default concurrency hint, used by the zero-argument io_context constructor.

View File

@ -38,7 +38,7 @@ epoll_reactor::epoll_reactor(asio::execution_context& ctx)
: execution_context_service_base<epoll_reactor>(ctx),
scheduler_(use_service<scheduler>(ctx)),
mutex_(ASIO_CONCURRENCY_HINT_IS_LOCKING(
SCHEDULER, scheduler_.concurrency_hint())),
REACTOR_REGISTRATION, scheduler_.concurrency_hint())),
interrupter_(),
epoll_fd_(do_epoll_create()),
timer_fd_(do_timerfd_create()),
@ -594,7 +594,8 @@ int epoll_reactor::do_timerfd_create()
epoll_reactor::descriptor_state* epoll_reactor::allocate_descriptor_state()
{
mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
return registered_descriptors_.alloc(registered_descriptors_mutex_.enabled());
return registered_descriptors_.alloc(ASIO_CONCURRENCY_HINT_IS_LOCKING(
REACTOR_IO, scheduler_.concurrency_hint()));
}
void epoll_reactor::free_descriptor_state(epoll_reactor::descriptor_state* s)

View File

@ -43,7 +43,7 @@ kqueue_reactor::kqueue_reactor(asio::execution_context& ctx)
: execution_context_service_base<kqueue_reactor>(ctx),
scheduler_(use_service<scheduler>(ctx)),
mutex_(ASIO_CONCURRENCY_HINT_IS_LOCKING(
SCHEDULER, scheduler_.concurrency_hint())),
REACTOR_REGISTRATION, scheduler_.concurrency_hint())),
kqueue_fd_(do_kqueue_create()),
interrupter_(),
shutdown_(false),
@ -498,7 +498,8 @@ int kqueue_reactor::do_kqueue_create()
kqueue_reactor::descriptor_state* kqueue_reactor::allocate_descriptor_state()
{
mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
return registered_descriptors_.alloc(registered_descriptors_mutex_.enabled());
return registered_descriptors_.alloc(ASIO_CONCURRENCY_HINT_IS_LOCKING(
REACTOR_IO, scheduler_.concurrency_hint()));
}
void kqueue_reactor::free_descriptor_state(kqueue_reactor::descriptor_state* s)