blob: 3e05b9e45e4ff886bcbeda78c77d56f006a59c70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "ticker_thread.h"
#include "simple_metrics_manager.h"
#include <chrono>
#include <vespa/log/log.h>
LOG_SETUP(".vespalib.metrics.ticker_thread");
namespace vespalib {
namespace metrics {
void
TickerThread::tickerLoop()
{
const std::chrono::seconds oneSec{1};
std::unique_lock<std::mutex> locker(_lock);
while (_runFlag) {
auto r = _cond.wait_for(locker, oneSec);
if (r == std::cv_status::timeout) {
_owner->tick();
}
}
}
void
TickerThread::stop()
{
if (_runFlag) {
std::unique_lock<std::mutex> locker(_lock);
_runFlag.store(false);
_cond.notify_all();
locker.unlock();
_thread.join();
}
}
} // namespace vespalib::metrics
} // namespace vespalib
|