blob: 1f8c249b99fe8ae5a8b0b0a260012027e3e5a0b0 (
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
40
41
42
43
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "time_bomb.h"
#include <cstdint>
#include <vespa/log/log.h>
LOG_SETUP(".vespalib.testkit.time_bomb");
namespace vespalib {
namespace {
void bomb(Gate &gate, vespalib::duration timeout) {
if (timeout > 5s) {
if (gate.await(timeout - 5s)) {
return;
}
}
size_t countdown = std::min(count_s(timeout), INT64_C(5));
while (countdown > 0) {
fprintf(stderr, "...%zu...\n", countdown--);
if (gate.await(1s)) {
return;
}
}
fprintf(stderr, "BOOM!\n");
LOG_ABORT("should not be reached");
}
} // namespace vespalib::<unnamed>
TimeBomb::TimeBomb(duration timeout)
: _gate(),
_thread(bomb, std::ref(_gate), timeout)
{
}
TimeBomb::~TimeBomb()
{
_gate.countDown();
_thread.join();
}
} // namespace vespalib
|