-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsaved_models_revision.cpp
More file actions
45 lines (36 loc) · 1.41 KB
/
Copy pathsaved_models_revision.cpp
File metadata and controls
45 lines (36 loc) · 1.41 KB
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
#include "saved_models_revision.hpp"
#include <atomic>
#include <utility>
namespace acecode {
namespace {
std::atomic<SavedModelsRevision> g_saved_models_revision{0};
void advance_saved_models_revision() noexcept {
// live_config is published by the caller before this release operation.
// Readers pair it with the acquire load below and the config owner's lock.
g_saved_models_revision.fetch_add(1, std::memory_order_release);
}
} // namespace
SavedModelsRevision current_saved_models_revision() noexcept {
return g_saved_models_revision.load(std::memory_order_acquire);
}
bool publish_live_config(AppConfig& live_config,
const AppConfig& persisted_config,
bool publish_saved_models_revision) {
const bool saved_models_changed = publish_saved_models_revision &&
!saved_model_lists_equal(live_config.saved_models,
persisted_config.saved_models);
live_config = persisted_config;
if (saved_models_changed) advance_saved_models_revision();
return saved_models_changed;
}
bool publish_live_saved_models(
AppConfig& live_config,
std::vector<ModelProfile> saved_models) {
if (saved_model_lists_equal(live_config.saved_models, saved_models)) {
return false;
}
live_config.saved_models = std::move(saved_models);
advance_saved_models_revision();
return true;
}
} // namespace acecode