blob: 2f69f69fc910f8ab938c86ed0a70eaeb4200a2bc (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <vespa/vespalib/metrics/clock.h>
namespace vespalib::metrics {
// share the MockTick between the tested and the tester.
class MockTick : public Tick {
private:
std::mutex _lock;
std::atomic<bool> _runFlag;
std::atomic<bool> _provided;
std::atomic<bool> _blocked;
std::condition_variable _providedCond;
std::condition_variable _blockedCond;
TimeStamp _nextValue;
TimeStamp _prevValue;
public:
MockTick();
TimeStamp next(TimeStamp prev) override;
void kill() override;
void provide(TimeStamp value);
TimeStamp waitUntilBlocked();
};
struct TickProxy : Tick {
std::shared_ptr<Tick> tick;
TickProxy(std::shared_ptr<Tick> tick_in) : tick(std::move(tick_in)) {}
TimeStamp next(TimeStamp prev) override { return tick->next(prev); }
void kill() override { tick->kill(); }
};
} // namespace vespalib::metrics
|