diff --git a/core/include/join/proactor.hpp b/core/include/join/proactor.hpp index 78b30cd6..ef956992 100644 --- a/core/include/join/proactor.hpp +++ b/core/include/join/proactor.hpp @@ -592,8 +592,9 @@ class join::BasicProactor : public join::EventHandler /** * @brief cancel all in-flight operations. + * @param flush submit the cancellations if true. */ - void cancelAllOperations () noexcept; + void cancelAllOperations (bool flush) noexcept; /** * @brief invoke function. diff --git a/core/include/join/proactor_epoll.hpp b/core/include/join/proactor_epoll.hpp index 3151245b..5ff6f85e 100644 --- a/core/include/join/proactor_epoll.hpp +++ b/core/include/join/proactor_epoll.hpp @@ -72,7 +72,7 @@ inline void join::BasicProactor::stop (bool sync) noexcept { if (isProactorThread ()) { - cancelAllOperations (); + cancelAllOperations (true); _reactor.stop (false); return; } @@ -82,7 +82,7 @@ inline void join::BasicProactor::stop (bool sync) noexcept return; } - writeCommand ({CommandType::Stop, nullptr, sync, nullptr, nullptr, nullptr}); + writeCommand ({CommandType::Stop, nullptr, true, nullptr, nullptr, nullptr}); if (JOIN_LIKELY (sync)) { @@ -400,7 +400,7 @@ inline void join::BasicProactor::processCommand (const Command& cmd) noexcept break; case CommandType::Stop: - cancelAllOperations (); + cancelAllOperations (cmd.flush); _reactor.stop (false); break; @@ -586,7 +586,7 @@ inline int join::BasicProactor::cancelOperation (IoOperation& op, [[maybe_unused // CLASS : BasicProactor // METHOD : cancelAllOperations // ========================================================================= -inline void join::BasicProactor::cancelAllOperations () noexcept +inline void join::BasicProactor::cancelAllOperations ([[maybe_unused]] bool flush) noexcept { for (size_t fd = 0; fd < _readOps.size (); ++fd) { diff --git a/core/include/join/proactor_uring.hpp b/core/include/join/proactor_uring.hpp index 9ca4ff1e..c062a83d 100644 --- a/core/include/join/proactor_uring.hpp +++ b/core/include/join/proactor_uring.hpp @@ -181,7 +181,7 @@ void join::BasicProactor::stop (bool sync) noexcept if (isProactorThread ()) { _running.store (false, std::memory_order_release); - cancelAllOperations (); + cancelAllOperations (true); return; } @@ -190,7 +190,7 @@ void join::BasicProactor::stop (bool sync) noexcept return; } - writeCommand ({CommandType::Stop, nullptr, sync, nullptr, nullptr, nullptr}); + writeCommand ({CommandType::Stop, nullptr, true, nullptr, nullptr, nullptr}); if (JOIN_LIKELY (sync)) { @@ -547,11 +547,7 @@ void join::BasicProactor::processCommand (const Command& cmd) noexcept case CommandType::Stop: _running.store (false, std::memory_order_release); - cancelAllOperations (); - if (JOIN_UNLIKELY (cmd.flush)) - { - io_uring_submit (&_ring); - } + cancelAllOperations (cmd.flush); break; case CommandType::Flush: @@ -720,7 +716,7 @@ int join::BasicProactor::cancelOperation (IoOperation& op, bool flush) // METHOD : cancelAllOperations // ========================================================================= template -void join::BasicProactor::cancelAllOperations () noexcept +void join::BasicProactor::cancelAllOperations (bool flush) noexcept { for (IoOperation* op : _pendingOps) { @@ -731,6 +727,11 @@ void join::BasicProactor::cancelAllOperations () noexcept } cancelOperation (*op, false); } + + if (JOIN_LIKELY (flush)) + { + io_uring_submit (&_ring); + } } // =========================================================================