From d958bfd0f32bfe798809b72c1b51c990edfe141c Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 15 Dec 2023 12:06:59 +0100 Subject: Core/Database: Replace DatabaseWorker with asio io_context --- src/common/Asio/IoContext.h | 17 ++++++++++++++++- src/common/Asio/Strand.h | 1 - 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/common/Asio') diff --git a/src/common/Asio/IoContext.h b/src/common/Asio/IoContext.h index b26de194b5c..4b469d3baa2 100644 --- a/src/common/Asio/IoContext.h +++ b/src/common/Asio/IoContext.h @@ -18,6 +18,7 @@ #ifndef IoContext_h__ #define IoContext_h__ +#include #include #include @@ -28,6 +29,8 @@ namespace Trinity class IoContext { public: + using Executor = boost::asio::io_context::executor_type; + IoContext() : _impl() { } explicit IoContext(int concurrency_hint) : _impl(concurrency_hint) { } @@ -35,9 +38,13 @@ namespace Trinity operator boost::asio::io_context const&() const { return _impl; } std::size_t run() { return _impl.run(); } + std::size_t poll() { return _impl.poll(); } void stop() { _impl.stop(); } - boost::asio::io_context::executor_type get_executor() noexcept { return _impl.get_executor(); } + bool stopped() const { return _impl.stopped(); } + void restart() { return _impl.restart(); } + + Executor get_executor() noexcept { return _impl.get_executor(); } private: boost::asio::io_context _impl; @@ -49,6 +56,14 @@ namespace Trinity return boost::asio::post(ioContext, std::forward(t)); } + template + inline decltype(auto) post(boost::asio::io_context::executor_type& executor, T&& t) + { + return boost::asio::post(executor, std::forward(t)); + } + + using boost::asio::bind_executor; + template inline decltype(auto) get_io_context(T&& ioObject) { diff --git a/src/common/Asio/Strand.h b/src/common/Asio/Strand.h index 942ddf55cd4..5228a30103b 100644 --- a/src/common/Asio/Strand.h +++ b/src/common/Asio/Strand.h @@ -19,7 +19,6 @@ #define Strand_h__ #include "IoContext.h" -#include #include namespace Trinity -- cgit v1.2.3