diff --git a/Inc/IPC/InputChannel.h b/Inc/IPC/InputChannel.h index 9cbe243..398ab56 100644 --- a/Inc/IPC/InputChannel.h +++ b/Inc/IPC/InputChannel.h @@ -29,7 +29,7 @@ namespace IPC template std::size_t ReceiveAll(Handler&& handler) { - return this->IsEmpty() ? 0 : ConsumeAll([&] { return this->GetQueue().ConsumeAll(handler); }); + return ConsumeAll([&] { return this->GetQueue().ConsumeAll(handler); }); } template @@ -44,11 +44,7 @@ namespace IPC this->GetNotEmptyEvent(), [this, receiver = m_receiverFactory(this->GetQueue(), std::forward(handler))]() mutable { - if (!this->IsEmpty()) - { - ConsumeAll(receiver); - } - + ConsumeAll(receiver); return true; }); @@ -77,20 +73,21 @@ namespace IPC template std::size_t ConsumeAll(Receiver&& receiver) { - assert(!this->IsEmpty()); - - auto memory = this->GetMemory(); // Make sure memory does not die if receiver deletes this. - auto& counter = this->GetCounter(); - - std::size_t n, count{ 0 }; - - do + if (auto& counter = this->GetCounter()) { - count += (n = receiver()); // Receiver may delete this. + auto memory = this->GetMemory(); // Make sure memory does not die if receiver deletes this. + std::size_t n, count{ 0 }; - } while ((counter -= n) != 0); + do + { + count += (n = receiver()); // Receiver may delete this. - return count; + } while ((counter -= n) != 0); + + return count; + } + + return 0; } using WaitHandle = decltype(std::declval()( diff --git a/Inc/IPC/Managed/detail/Interop/Policies/ReceiverFactory.h b/Inc/IPC/Managed/detail/Interop/Policies/ReceiverFactory.h index b727df7..fe16290 100644 --- a/Inc/IPC/Managed/detail/Interop/Policies/ReceiverFactory.h +++ b/Inc/IPC/Managed/detail/Interop/Policies/ReceiverFactory.h @@ -31,10 +31,10 @@ namespace Managed queueWorkItem( [&queue, &handler] { - auto value = queue.Pop(); - assert(value); - - handler(std::move(*value)); + if (auto&& value = queue.Pop()) + { + handler(std::move(*value)); + } }); return 1; diff --git a/Inc/IPC/Policies/AsyncReceiverFactory.h b/Inc/IPC/Policies/AsyncReceiverFactory.h index c6c363a..bde6aac 100644 --- a/Inc/IPC/Policies/AsyncReceiverFactory.h +++ b/Inc/IPC/Policies/AsyncReceiverFactory.h @@ -26,9 +26,10 @@ namespace Policies return Scheduler{ [&queue, handler = std::forward(handler)] { - auto&& value = queue.Pop(); - assert(value); - handler(std::move(*value)); + if (auto&& value = queue.Pop()) + { + handler(std::move(*value)); + } }, m_pool }; }