forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown.cpp
More file actions
42 lines (34 loc) · 894 Bytes
/
shutdown.cpp
File metadata and controls
42 lines (34 loc) · 894 Bytes
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
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/shutdown.hpp"
#include <functional>
#include <vector>
namespace ov {
class ShutdownRegistry {
private:
std::vector<std::function<void()>> m_callbacks;
ShutdownRegistry() = default;
public:
static ShutdownRegistry& get() {
static ShutdownRegistry instance;
return instance;
}
bool register_callback(const std::function<void()>& func) {
if (!func) {
return false;
}
m_callbacks.emplace_back(func);
return true;
}
~ShutdownRegistry() {
for (auto& func : m_callbacks) {
func();
}
m_callbacks.clear();
}
};
bool register_shutdown_callback(const std::function<void()>& func) {
return ShutdownRegistry::get().register_callback(func);
}
} // namespace ov