diff --git a/src/Logger.cpp b/src/Logger.cpp index 718d5e5..1d6d25d 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -188,20 +188,21 @@ 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 (!mStop) { + return nullptr; } 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); + } } } }