mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 18:11:33 +08:00
Update periodic_worker.h
This commit is contained in:
parent
5fd56ec463
commit
40aeaaee54
@ -34,21 +34,17 @@ public:
|
|||||||
}
|
}
|
||||||
active_ = true;
|
active_ = true;
|
||||||
flusher_thread_ = std::thread([callback_fun, interval, this]() {
|
flusher_thread_ = std::thread([callback_fun, interval, this]() {
|
||||||
using std::chrono::steady_clock;
|
|
||||||
|
|
||||||
auto last_flush_tp = steady_clock::now();
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(this->mutex_);
|
std::unique_lock<std::mutex> lock(this->mutex_);
|
||||||
this->cv_.wait_for(lock, interval, [callback_fun, interval, last_flush_tp, this] {
|
bool should_terminate = this->cv_.wait_for(lock, interval, [this] {
|
||||||
return !this->active_ || (steady_clock::now() - last_flush_tp) >= interval;
|
return !this->active_;
|
||||||
});
|
});
|
||||||
if (!this->active_)
|
if (should_terminate)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
callback_fun();
|
callback_fun();
|
||||||
last_flush_tp = steady_clock::now();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user