diff options
Diffstat (limited to '3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp')
-rw-r--r-- | 3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp b/3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp index 6ba64583ecf..60b5ca861ee 100644 --- a/3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp +++ b/3rdparty/asio/include/asio/detail/impl/kqueue_reactor.ipp @@ -2,7 +2,7 @@ // detail/impl/kqueue_reactor.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2005 Stefan Arentz (stefan at soze dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -25,9 +25,13 @@ #include "asio/detail/throw_error.hpp" #include "asio/error.hpp" +#if defined(__NetBSD__) +# include <sys/param.h> +#endif + #include "asio/detail/push_options.hpp" -#if defined(__NetBSD__) +#if defined(__NetBSD__) && __NetBSD_Version__ < 999001500 # define ASIO_KQUEUE_EV_SET(ev, ident, filt, flags, fflags, data, udata) \ EV_SET(ev, ident, filt, flags, fflags, data, \ reinterpret_cast<intptr_t>(static_cast<void*>(udata))) @@ -43,7 +47,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), @@ -282,6 +286,35 @@ void kqueue_reactor::cancel_ops(socket_type, scheduler_.post_deferred_completions(ops); } +void kqueue_reactor::cancel_ops_by_key(socket_type, + kqueue_reactor::per_descriptor_data& descriptor_data, + int op_type, void* cancellation_key) +{ + if (!descriptor_data) + return; + + mutex::scoped_lock descriptor_lock(descriptor_data->mutex_); + + op_queue<operation> ops; + op_queue<reactor_op> other_ops; + while (reactor_op* op = descriptor_data->op_queue_[op_type].front()) + { + descriptor_data->op_queue_[op_type].pop(); + if (op->cancellation_key_ == cancellation_key) + { + op->ec_ = asio::error::operation_aborted; + ops.push(op); + } + else + other_ops.push(op); + } + descriptor_data->op_queue_[op_type].push(other_ops); + + descriptor_lock.unlock(); + + scheduler_.post_deferred_completions(ops); +} + void kqueue_reactor::deregister_descriptor(socket_type descriptor, kqueue_reactor::per_descriptor_data& descriptor_data, bool closing) { @@ -327,10 +360,16 @@ void kqueue_reactor::deregister_descriptor(socket_type descriptor, context(), static_cast<uintmax_t>(descriptor), reinterpret_cast<uintmax_t>(descriptor_data))); - free_descriptor_state(descriptor_data); - descriptor_data = 0; - scheduler_.post_deferred_completions(ops); + + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; } } @@ -364,6 +403,22 @@ void kqueue_reactor::deregister_internal_descriptor(socket_type descriptor, context(), static_cast<uintmax_t>(descriptor), reinterpret_cast<uintmax_t>(descriptor_data))); + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; + } +} + +void kqueue_reactor::cleanup_descriptor_data( + per_descriptor_data& descriptor_data) +{ + if (descriptor_data) + { free_descriptor_state(descriptor_data); descriptor_data = 0; } @@ -498,7 +553,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) |