proxygen
folly::settings::detail Namespace Reference

Classes

class  SettingCore
 
class  SettingWrapper
 
class  SnapshotSettingWrapper
 
struct  TypeIdentity
 

Typedefs

template<class T >
using TypeIdentityT = typename TypeIdentity< T >::type
 

Functions

 if (savedValue)
 
return core getSlow ()
 
template<class T >
void set (detail::SettingCore< T > &core, const T &t, StringPiece reason)
 
template<class T >
std::enable_if_t< std::is_constructible< T, StringPiece >::value, TconvertOrConstruct (StringPiece newValue)
 
template<class T >
std::enable_if_t<!std::is_constructible< T, StringPiece >::value, TconvertOrConstruct (StringPiece newValue)
 
void registerSetting (SettingCoreBase &core)
 
auto & getSavedValuesMutex ()
 
auto & getSavedValues ()
 
SettingCoreBase::Version nextGlobalVersion ()
 
void saveValueForOutstandingSnapshots (SettingCoreBase::Key settingKey, SettingCoreBase::Version version, const BoxedValue &value)
 
const BoxedValue *FOLLY_NULLABLE getSavedValue (SettingCoreBase::Key settingKey, SettingCoreBase::Version at)
 

Variables

template<class T >
auto savedValue = detail::getSavedValue(core.getKey(), at_)
 
std::atomic< SettingCoreBase::Version > gGlobalVersion_
 

Typedef Documentation

template<class T >
using folly::settings::detail::TypeIdentityT = typedef typename TypeIdentity<T>::type

Definition at line 89 of file Settings.h.

Function Documentation

template<class T >
std::enable_if_t<std::is_constructible<T, StringPiece>::value, T> folly::settings::detail::convertOrConstruct ( StringPiece  newValue)

Definition at line 239 of file SettingsImpl.h.

References folly::T, and value.

239  {
240  return T(newValue);
241 }
#define T(v)
Definition: http_parser.c:233
template<class T >
std::enable_if_t<!std::is_constructible<T, StringPiece>::value, T> folly::settings::detail::convertOrConstruct ( StringPiece  newValue)

Definition at line 244 of file SettingsImpl.h.

244  {
245  return to<T>(newValue);
246 }
const BoxedValue* FOLLY_NULLABLE folly::settings::detail::getSavedValue ( SettingCoreBase::Key  settingKey,
SettingCoreBase::Version  at 
)

Definition at line 142 of file Settings.cpp.

References folly::test::end(), getSavedValues(), getSavedValuesMutex(), and gGlobalVersion_.

142  {
143  SharedMutex::ReadHolder lg(getSavedValuesMutex());
144  auto it = getSavedValues().find(at);
145  if (it != getSavedValues().end()) {
146  auto jt = it->second.second.find(settingKey);
147  if (jt != it->second.second.end()) {
148  return &jt->second;
149  }
150  }
151  return nullptr;
152 }
auto & getSavedValuesMutex()
Definition: Settings.cpp:111
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
auto& folly::settings::detail::getSavedValues ( )

Definition at line 117 of file Settings.cpp.

Referenced by getSavedValue(), and saveValueForOutstandingSnapshots().

117  {
118  static std::unordered_map<
119  SettingCoreBase::Version,
120  std::pair<size_t, std::unordered_map<SettingCoreBase::Key, BoxedValue>>>
121  gSavedValues;
122  return gSavedValues;
123 }
auto& folly::settings::detail::getSavedValuesMutex ( )

Definition at line 111 of file Settings.cpp.

Referenced by getSavedValue(), and saveValueForOutstandingSnapshots().

111  {
112  static SharedMutex gSavedValuesMutex;
113  return gSavedValuesMutex;
114 }
SharedMutexWritePriority SharedMutex
Definition: SharedMutex.h:1511
folly::settings::detail::if ( savedValue  )

Definition at line 225 of file SettingsImpl.h.

References savedValue.

225  {
226  return savedValue->template unbox<T>();
227  }
SettingCoreBase::Version folly::settings::detail::nextGlobalVersion ( )

Definition at line 125 of file Settings.cpp.

Referenced by folly::settings::detail::SettingCore< T >::set().

125  {
126  return gGlobalVersion_.fetch_add(1) + 1;
127 }
std::atomic< SettingCoreBase::Version > gGlobalVersion_
Definition: Settings.cpp:109
void folly::settings::detail::registerSetting ( SettingCoreBase &  core)

Definition at line 33 of file Settings.cpp.

References folly::gen::move.

Referenced by folly::settings::detail::SettingCore< T >::SettingCore().

33  {
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());
39  }
40 
41  auto fullname = core.meta().project.str() + "_" + core.meta().name.str();
42 
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);
47  }
48  mapPtr->emplace(std::move(fullname), &core);
49 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void folly::settings::detail::saveValueForOutstandingSnapshots ( SettingCoreBase::Key  settingKey,
SettingCoreBase::Version  version,
const BoxedValue &  value 
)

Definition at line 129 of file Settings.cpp.

References FOLLY_NULLABLE, getSavedValues(), getSavedValuesMutex(), and folly::value().

Referenced by folly::settings::detail::SettingCore< T >::set().

132  {
133  SharedMutex::WriteHolder lg(getSavedValuesMutex());
134  for (auto& it : getSavedValues()) {
135  if (version <= it.first) {
136  it.second.second[settingKey] = value;
137  }
138  }
139 }
auto & getSavedValuesMutex()
Definition: Settings.cpp:111
ProtocolVersion version
static const char *const value
Definition: Conv.cpp:50
template<class T >
void folly::settings::detail::set ( detail::SettingCore< T > &  core,
const T t,
StringPiece  reason 
)

Definition at line 232 of file SettingsImpl.h.

References folly::T, and value.

232  {
233  snapshotValues_[core.getKey()] = detail::BoxedValue(t, reason, core);
234  }

Variable Documentation

std::atomic<SettingCoreBase::Version> folly::settings::detail::gGlobalVersion_

Definition at line 109 of file Settings.cpp.

Referenced by getSavedValue().

template<class T >
auto folly::settings::detail::savedValue = detail::getSavedValue(core.getKey(), at_)

Can we store T in a global atomic?

Definition at line 224 of file SettingsImpl.h.

Referenced by if().