blob: 8b67b1779cd38635fdf82f92c8d6f2cc57e62f22 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "configholder.h"
namespace config {
ConfigHolder::ConfigHolder()
: _lock(),
_cond(),
_current()
{
}
ConfigHolder::~ConfigHolder() = default;
std::unique_ptr<ConfigUpdate>
ConfigHolder::provide()
{
std::lock_guard guard(_lock);
return std::move(_current);
}
void
ConfigHolder::handle(std::unique_ptr<ConfigUpdate> update)
{
std::lock_guard guard(_lock);
if (_current) {
update->merge(*_current);
}
_current = std::move(update);
_cond.notify_all();
}
bool
ConfigHolder::wait_until(vespalib::steady_time deadline)
{
std::unique_lock guard(_lock);
return static_cast<bool>(_current) || (_cond.wait_until(guard, deadline) == std::cv_status::no_timeout);
}
bool
ConfigHolder::poll()
{
std::lock_guard guard(_lock);
return static_cast<bool>(_current);
}
void
ConfigHolder::close()
{
std::lock_guard guard(_lock);
_current.reset();
_cond.notify_all();
}
} // namespace config
|