Skip to content

Commit

Permalink
Update vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Aug 13, 2023
1 parent 0b43fc6 commit 6a44ad4
Show file tree
Hide file tree
Showing 38 changed files with 612 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include <memory>
#include <utility>
#include "asio/any_completion_executor.hpp"
#include "asio/any_io_executor.hpp"
#include "asio/associated_allocator.hpp"
#include "asio/associated_cancellation_slot.hpp"
#include "asio/associated_executor.hpp"
#include "asio/associated_immediate_executor.hpp"
#include "asio/cancellation_state.hpp"
#include "asio/recycling_allocator.hpp"

Expand Down Expand Up @@ -125,6 +127,13 @@ class any_completion_handler_impl :
(get_associated_executor)(handler_, candidate));
}

any_completion_executor immediate_executor(
const any_io_executor& candidate) const ASIO_NOEXCEPT
{
return any_completion_executor(std::nothrow,
(get_associated_immediate_executor)(handler_, candidate));
}

void* allocate(std::size_t size, std::size_t align) const
{
typename std::allocator_traits<
Expand Down Expand Up @@ -305,6 +314,36 @@ class any_completion_handler_executor_fn
type executor_fn_;
};

class any_completion_handler_immediate_executor_fn
{
public:
using type = any_completion_executor(*)(
any_completion_handler_impl_base*, const any_io_executor&);

constexpr any_completion_handler_immediate_executor_fn(type fn)
: immediate_executor_fn_(fn)
{
}

any_completion_executor immediate_executor(
any_completion_handler_impl_base* impl,
const any_io_executor& candidate) const
{
return immediate_executor_fn_(impl, candidate);
}

template <typename Handler>
static any_completion_executor impl(any_completion_handler_impl_base* impl,
const any_io_executor& candidate)
{
return static_cast<any_completion_handler_impl<Handler>*>(
impl)->immediate_executor(candidate);
}

private:
type immediate_executor_fn_;
};

class any_completion_handler_allocate_fn
{
public:
Expand Down Expand Up @@ -367,6 +406,7 @@ template <typename... Signatures>
class any_completion_handler_fn_table
: private any_completion_handler_destroy_fn,
private any_completion_handler_executor_fn,
private any_completion_handler_immediate_executor_fn,
private any_completion_handler_allocate_fn,
private any_completion_handler_deallocate_fn,
private any_completion_handler_call_fns<Signatures...>
Expand All @@ -376,11 +416,13 @@ class any_completion_handler_fn_table
constexpr any_completion_handler_fn_table(
any_completion_handler_destroy_fn::type destroy_fn,
any_completion_handler_executor_fn::type executor_fn,
any_completion_handler_immediate_executor_fn::type immediate_executor_fn,
any_completion_handler_allocate_fn::type allocate_fn,
any_completion_handler_deallocate_fn::type deallocate_fn,
CallFns... call_fns)
: any_completion_handler_destroy_fn(destroy_fn),
any_completion_handler_executor_fn(executor_fn),
any_completion_handler_immediate_executor_fn(immediate_executor_fn),
any_completion_handler_allocate_fn(allocate_fn),
any_completion_handler_deallocate_fn(deallocate_fn),
any_completion_handler_call_fns<Signatures...>(call_fns...)
Expand All @@ -389,6 +431,7 @@ class any_completion_handler_fn_table

using any_completion_handler_destroy_fn::destroy;
using any_completion_handler_executor_fn::executor;
using any_completion_handler_immediate_executor_fn::immediate_executor;
using any_completion_handler_allocate_fn::allocate;
using any_completion_handler_deallocate_fn::deallocate;
using any_completion_handler_call_fns<Signatures...>::call;
Expand All @@ -401,6 +444,7 @@ struct any_completion_handler_fn_table_instance
value = any_completion_handler_fn_table<Signatures...>(
&any_completion_handler_destroy_fn::impl<Handler>,
&any_completion_handler_executor_fn::impl<Handler>,
&any_completion_handler_immediate_executor_fn::impl<Handler>,
&any_completion_handler_allocate_fn::impl<Handler>,
&any_completion_handler_deallocate_fn::impl<Handler>,
&any_completion_handler_call_fn<Signatures>::template impl<Handler>...);
Expand Down Expand Up @@ -576,6 +620,9 @@ class any_completion_handler
template <typename, typename>
friend struct associated_executor;

template <typename, typename>
friend struct associated_immediate_executor;

const detail::any_completion_handler_fn_table<Signatures...>* fn_table_;
detail::any_completion_handler_impl_base* impl_;
#endif // !defined(GENERATING_DOCUMENTATION)
Expand Down Expand Up @@ -750,6 +797,20 @@ struct associated_executor<any_completion_handler<Signatures...>, Candidate>
}
};

template <typename... Signatures, typename Candidate>
struct associated_immediate_executor<
any_completion_handler<Signatures...>, Candidate>
{
using type = any_completion_executor;

static type get(const any_completion_handler<Signatures...>& handler,
const Candidate& candidate = Candidate()) ASIO_NOEXCEPT
{
return handler.fn_table_->immediate_executor(handler.impl_,
any_io_executor(std::nothrow, candidate));
}
};

} // namespace asio

#include "asio/detail/pop_options.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@
# include <unistd.h>
#endif // defined(ASIO_HAS_UNISTD_H)

// Linux: epoll, eventfd and timerfd.
// Linux: epoll, eventfd, timerfd and io_uring.
#if defined(__linux__)
# include <linux/version.h>
# if !defined(ASIO_HAS_EPOLL)
Expand All @@ -1730,6 +1730,11 @@
# endif // (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8)
# endif // defined(ASIO_HAS_EPOLL)
# endif // !defined(ASIO_HAS_TIMERFD)
# if defined(ASIO_HAS_IO_URING)
# if LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0)
# error Linux kernel 5.10 or later is required to support io_uring
# endif // LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0)
# endif // defined(ASIO_HAS_IO_URING)
#endif // defined(__linux__)

// Linux: io_uring is used instead of epoll.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ class dev_poll_reactor
{
start_op(op_type, descriptor, descriptor_data,
op, is_continuation, allow_speculative,
&epoll_reactor::call_post_immediate_completion, this);
&dev_poll_reactor::call_post_immediate_completion, this);
}


// Cancel all operations associated with the given descriptor. The
// handlers associated with the descriptor will be invoked with the
// operation_aborted error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,53 +435,58 @@ void io_uring_service::run(long usec, op_queue<operation>& ops)
? ::io_uring_peek_cqe(&ring_, &cqe)
: ::io_uring_wait_cqe(&ring_, &cqe);

if (result == 0 && usec > 0)
if (local_ops > 0)
{
if (::io_uring_cqe_get_data(cqe) != &ts)
if (result != 0 || ::io_uring_cqe_get_data(cqe) != &ts)
{
mutex::scoped_lock lock(mutex_);
if (::io_uring_sqe* sqe = get_sqe())
{
++local_ops;
::io_uring_prep_timeout_remove(sqe, reinterpret_cast<__u64>(&ts), 0);
::io_uring_sqe_set_data(sqe, &ts);
submit_sqes();
}
}
}

bool check_timers = false;
int count = 0;
while (result == 0)
while (result == 0 || local_ops > 0)
{
if (void* ptr = ::io_uring_cqe_get_data(cqe))
if (result == 0)
{
if (ptr == this)
if (void* ptr = ::io_uring_cqe_get_data(cqe))
{
// The io_uring service was interrupted.
}
else if (ptr == &timer_queues_)
{
check_timers = true;
}
else if (ptr == &timeout_)
{
check_timers = true;
timeout_.tv_sec = 0;
timeout_.tv_nsec = 0;
}
else if (ptr == &ts)
{
--local_ops;
}
else
{
io_queue* io_q = static_cast<io_queue*>(ptr);
io_q->set_result(cqe->res);
ops.push(io_q);
if (ptr == this)
{
// The io_uring service was interrupted.
}
else if (ptr == &timer_queues_)
{
check_timers = true;
}
else if (ptr == &timeout_)
{
check_timers = true;
timeout_.tv_sec = 0;
timeout_.tv_nsec = 0;
}
else if (ptr == &ts)
{
--local_ops;
}
else
{
io_queue* io_q = static_cast<io_queue*>(ptr);
io_q->set_result(cqe->res);
ops.push(io_q);
}
}
::io_uring_cqe_seen(&ring_, cqe);
++count;
}
::io_uring_cqe_seen(&ring_, cqe);
result = (++count < complete_batch_size || local_ops > 0)
result = (count < complete_batch_size || local_ops > 0)
? ::io_uring_peek_cqe(&ring_, &cqe) : -EAGAIN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ asio::error_code signal_set_service::add(
if (state->flags_[signal_number] != signal_set_base::flags::dont_care)
{
ec = asio::error::invalid_argument;
delete new_registration;
return ec;
}
struct sigaction sa;
Expand All @@ -397,6 +398,7 @@ asio::error_code signal_set_service::add(
{
ec = asio::error_code(errno,
asio::error::get_system_category());
delete new_registration;
return ec;
}
state->flags_[signal_number] = f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ class reactive_socket_service_base
{
public:
reactor_op_cancellation(reactor* r,
reactor::per_descriptor_data* p, int d, int o)
reactor::per_descriptor_data* p, socket_type d, int o)
: reactor_(r),
reactor_data_(p),
descriptor_(d),
Expand All @@ -723,7 +723,7 @@ class reactive_socket_service_base
private:
reactor* reactor_;
reactor::per_descriptor_data* reactor_data_;
int descriptor_;
socket_type descriptor_;
int op_type_;
};

Expand Down
Loading

0 comments on commit 6a44ad4

Please sign in to comment.