forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_manager_impl.cc
48 lines (41 loc) · 1.26 KB
/
init_manager_impl.cc
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
#include "server/init_manager_impl.h"
#include <functional>
#include "common/common/assert.h"
namespace Envoy {
namespace Server {
void InitManagerImpl::initialize(std::function<void()> callback) {
ASSERT(state_ == State::NotInitialized);
if (targets_.empty()) {
callback();
state_ = State::Initialized;
} else {
callback_ = callback;
state_ = State::Initializing;
// Target::initialize(...) method can modify the list to remove the item currently
// being initialized, so we increment the iterator before calling initialize.
for (auto iter = targets_.begin(); iter != targets_.end();) {
Init::Target* target = *iter;
++iter;
initializeTarget(*target);
}
}
}
void InitManagerImpl::initializeTarget(Init::Target& target) {
target.initialize([this, &target]() -> void {
ASSERT(std::find(targets_.begin(), targets_.end(), &target) != targets_.end());
targets_.remove(&target);
if (targets_.empty()) {
state_ = State::Initialized;
callback_();
}
});
}
void InitManagerImpl::registerTarget(Init::Target& target) {
ASSERT(state_ != State::Initialized);
targets_.push_back(&target);
if (state_ == State::Initializing) {
initializeTarget(target);
}
}
} // namespace Server
} // namespace Envoy