From 3c2a53d58f658b78ac9103b825f713e27cde8b4d Mon Sep 17 00:00:00 2001 From: u6th9d Date: Tue, 9 Oct 2018 16:46:13 +0800 Subject: [PATCH 1/3] Update Logger.cpp Should not lose the log :) --- src/Logger.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Logger.cpp b/src/Logger.cpp index 718d5e5..84eab64 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -188,20 +188,18 @@ LogUnit* Logger::getLogUnit() } } else { std::unique_lock lck(mMtx); - if (!mFree.empty()) { - log = mFree.back(); - mFree.resize(mFree.size() - 1); - } else if (mLogUnitCnt < mFree.capacity()) { - ++mLogUnitCnt; - } else { - while (mFree.empty() && !mStop) { - mCond.wait(lck); - } + while (true) { if (!mFree.empty()) { log = mFree.back(); mFree.resize(mFree.size() - 1); + break; + } else if (mLogUnitCnt < mFree.capacity()) { + ++mLogUnitCnt; + break; } else { - return nullptr; + while (mFree.empty() && !mStop) { + mCond.wait(lck); + } } } } From 885fb4eca92618cdd64bc40391ffb1ee508762f6 Mon Sep 17 00:00:00 2001 From: u6th9d Date: Tue, 9 Oct 2018 20:42:34 +0800 Subject: [PATCH 2/3] Update Logger.cpp --- src/Logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Logger.cpp b/src/Logger.cpp index 84eab64..6dab2cf 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -188,7 +188,7 @@ LogUnit* Logger::getLogUnit() } } else { std::unique_lock lck(mMtx); - while (true) { + while (!mStop) { if (!mFree.empty()) { log = mFree.back(); mFree.resize(mFree.size() - 1); From 354bde290d5d46fc7d2c9975ce518e2a5c5b5d2d Mon Sep 17 00:00:00 2001 From: u6th9d Date: Sat, 13 Oct 2018 23:25:13 +0800 Subject: [PATCH 3/3] Update Logger.cpp --- src/Logger.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Logger.cpp b/src/Logger.cpp index 6dab2cf..1d6d25d 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -188,7 +188,10 @@ LogUnit* Logger::getLogUnit() } } else { std::unique_lock lck(mMtx); - while (!mStop) { + while (true) { + if (!mStop) { + return nullptr; + } if (!mFree.empty()) { log = mFree.back(); mFree.resize(mFree.size() - 1);