Skip to content

Commit b2882ef

Browse files
committed
[perf] change USemaphore cv.wait condition
1 parent cabc0af commit b2882ef

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class USemaphore : public UThreadObject {
3535
CVoid wait() {
3636
CGRAPH_UNIQUE_LOCK lk(mutex_);
3737
cnt_--;
38-
while (cnt_ < 0) {
39-
cv_.wait(lk);
40-
}
38+
cv_.wait(lk, [this] {
39+
return cnt_ < 0;
40+
});
4141
}
4242

4343
private:
44-
CInt cnt_ = 0; // 记录当前的次数
44+
CInt cnt_ { 0 }; // 记录当前的次数
4545
std::mutex mutex_;
4646
std::condition_variable cv_;
4747
};

0 commit comments

Comments
 (0)