26 using SettingsMap = std::map<std::string, SettingCoreBase*>;
27 Synchronized<SettingsMap>& settingsMap() {
28 static Indestructible<Synchronized<SettingsMap>>
map;
34 if (core.meta().project.empty() ||
35 core.meta().project.find(
'_') != std::string::npos) {
36 throw std::logic_error(
37 "Setting project must be nonempty and cannot contain underscores: " +
38 core.meta().project.str());
41 auto fullname = core.meta().project.str() +
"_" + core.meta().name.str();
43 auto mapPtr = settingsMap().wlock();
44 auto it = mapPtr->find(fullname);
45 if (it != mapPtr->end()) {
46 throw std::logic_error(
"FOLLY_SETTING already exists: " + fullname);
48 mapPtr->emplace(
std::move(fullname), &core);
54 auto mapPtr = detail::settingsMap().rlock();
55 auto it = mapPtr->find(settingName.
str());
56 if (it == mapPtr->end()) {
59 return it->second->meta();
66 auto mapPtr = detail::settingsMap().rlock();
67 auto it = mapPtr->find(settingName.
str());
68 if (it == mapPtr->end()) {
71 it->second->setFromString(newValue, reason,
this);
77 auto mapPtr = detail::settingsMap().rlock();
78 auto it = mapPtr->find(settingName.
str());
79 if (it == mapPtr->end()) {
82 return it->second->getAsString(
this);
86 auto mapPtr = detail::settingsMap().rlock();
87 auto it = mapPtr->find(settingName.
str());
88 if (it == mapPtr->end()) {
91 it->second->resetToDefault(
this);
98 detail::SettingsMap
map;
101 map = *detail::settingsMap().rlock();
102 for (
const auto& kv : map) {
103 auto value = kv.second->getAsString(
this);
104 func(kv.second->meta(),
value.first,
value.second);
113 return gSavedValuesMutex;
118 static std::unordered_map<
119 SettingCoreBase::Version,
120 std::pair<size_t, std::unordered_map<SettingCoreBase::Key, BoxedValue>>>
126 return gGlobalVersion_.fetch_add(1) + 1;
131 SettingCoreBase::Version
version,
132 const BoxedValue&
value) {
135 if (version <= it.first) {
136 it.second.second[settingKey] =
value;
146 auto jt = it->second.second.find(settingKey);
147 if (jt != it->second.second.end()) {
154 SnapshotBase::SnapshotBase() {
158 std::piecewise_construct,
159 std::forward_as_tuple(at_),
160 std::forward_as_tuple());
161 ++it.first->second.first;
164 SnapshotBase::~SnapshotBase() {
169 if (!it->second.first) {
177 for (
auto& it : snapshotValues_) {
SettingCoreBase::Version nextGlobalVersion()
bool setFromString(StringPiece settingName, StringPiece newValue, StringPiece reason) override
auto & getSavedValuesMutex()
constexpr detail::Map< Move > move
internal::KeyMatcher< M > Key(M inner_matcher)
static http_parser_settings settings
—— Concurrent Priority Queue Implementation ——
void saveValueForOutstandingSnapshots(SettingCoreBase::Key settingKey, SettingCoreBase::Version version, const BoxedValue &value)
const BoxedValue *FOLLY_NULLABLE getSavedValue(SettingCoreBase::Key settingKey, SettingCoreBase::Version at)
auto end(TestAdlIterable &instance)
void forEachSetting(const std::function< void(const SettingMetadata &, StringPiece, StringPiece)> &func) const override
void registerSetting(SettingCoreBase &core)
std::atomic< SettingCoreBase::Version > gGlobalVersion_
Optional< SettingMetadata > getSettingsMeta(StringPiece settingName)
Optional< SettingsInfo > getAsString(StringPiece settingName) const override
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
bool resetToDefault(StringPiece settingName) override