From c111145902e2c4f8929ff2dd42ce6680c697f830 Mon Sep 17 00:00:00 2001 From: Zifeng Deng Date: Sun, 12 Nov 2023 00:16:55 +0800 Subject: [PATCH] feat(co): warn coroutine leak instead of assert --- lib/co_context/co/semaphore.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/co_context/co/semaphore.cpp b/lib/co_context/co/semaphore.cpp index d9f02cf..3f865b5 100644 --- a/lib/co_context/co/semaphore.cpp +++ b/lib/co_context/co/semaphore.cpp @@ -10,8 +10,12 @@ namespace co_context { counting_semaphore::~counting_semaphore() noexcept { - assert(awaiting.load(std::memory_order_relaxed) == nullptr); - assert(to_resume == nullptr); + if constexpr (config::is_log_d) { + if (awaiting.load(std::memory_order_relaxed) != nullptr + || to_resume != nullptr) { + log::d("[WARNING] ~counting_semaphore(): coroutine leak\n"); + } + } } bool counting_semaphore::try_acquire() noexcept {