proxygen
folly::settings::detail::SettingCore< T > Class Template Reference

#include <SettingsImpl.h>

Inheritance diagram for folly::settings::detail::SettingCore< T >:

Public Types

using Contents = SettingContents< T >
 

Public Member Functions

void setFromString (StringPiece newValue, StringPiece reason, SnapshotBase *snapshot) override
 
std::pair< std::string, std::stringgetAsString (const SnapshotBase *snapshot) const override
 
void resetToDefault (SnapshotBase *snapshot) override
 
const SettingMetadatameta () const override
 
std::conditional_t< IsSmallPOD< T >::value, T, const T & > getWithHint (std::atomic< uint64_t > &trivialStorage) const
 
const SettingContents< T > & getSlow () const
 
T getImpl (std::true_type, std::atomic< uint64_t > &trivialStorage) const
 
const TgetImpl (std::false_type, std::atomic< uint64_t > &) const
 
void set (const T &t, StringPiece reason, SnapshotBase *snapshot=nullptr)
 
const TdefaultValue () const
 
 SettingCore (SettingMetadata meta, T defaultValue, std::atomic< uint64_t > &trivialStorage)
 

Private Member Functions

FOLLY_ALWAYS_INLINE const std::shared_ptr< Contents > & tlValue () const
 
FOLLY_NOINLINE const std::shared_ptr< Contents > & tlValueSlow () const
 

Private Attributes

SettingMetadata meta_
 
const T defaultValue_
 
SharedMutex globalLock_
 
std::shared_ptr< ContentsglobalValue_
 
std::atomic< uint64_t > & trivialStorage_
 
CachelinePadded< std::atomic< Version > > settingVersion_ {1}
 
ThreadLocal< CachelinePadded< std::pair< Version, std::shared_ptr< Contents > > > > localValue_
 

Detailed Description

template<class T>
class folly::settings::detail::SettingCore< T >

Definition at line 249 of file SettingsImpl.h.

Member Typedef Documentation

template<class T>
using folly::settings::detail::SettingCore< T >::Contents = SettingContents<T>

Definition at line 251 of file SettingsImpl.h.

Constructor & Destructor Documentation

template<class T>
folly::settings::detail::SettingCore< T >::SettingCore ( SettingMetadata  meta,
T  defaultValue,
std::atomic< uint64_t > &  trivialStorage 
)
inline

Definition at line 334 of file SettingsImpl.h.

References folly::settings::detail::registerSetting().

338  : meta_(std::move(meta)),
340  trivialStorage_(trivialStorage),
341  localValue_([]() {
342  return new CachelinePadded<
343  std::pair<Version, std::shared_ptr<Contents>>>(0, nullptr);
344  }) {
345  set(defaultValue_, "default");
346  registerSetting(*this);
347  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const SettingMetadata & meta() const override
Definition: SettingsImpl.h:271
std::atomic< uint64_t > & trivialStorage_
Definition: SettingsImpl.h:356
ThreadLocal< CachelinePadded< std::pair< Version, std::shared_ptr< Contents > > > > localValue_
Definition: SettingsImpl.h:363
void registerSetting(SettingCoreBase &core)
Definition: Settings.cpp:33

Member Function Documentation

template<class T>
const T& folly::settings::detail::SettingCore< T >::defaultValue ( ) const
inline

Definition at line 330 of file SettingsImpl.h.

330  {
331  return defaultValue_;
332  }
template<class T>
std::pair<std::string, std::string> folly::settings::detail::SettingCore< T >::getAsString ( const SnapshotBase *  snapshot) const
inlineoverride

Definition at line 260 of file SettingsImpl.h.

References folly::settings::detail::getSlow().

261  {
262  auto& contents = snapshot ? snapshot->get(*this) : getSlow();
263  return std::make_pair(
264  to<std::string>(contents.value), contents.updateReason);
265  }
const SettingContents< T > & getSlow() const
Definition: SettingsImpl.h:285
template<class T>
T folly::settings::detail::SettingCore< T >::getImpl ( std::true_type  ,
std::atomic< uint64_t > &  trivialStorage 
) const
inline

Definition at line 291 of file SettingsImpl.h.

References folly::pushmi::detail::t, and uint64_t.

291  {
292  uint64_t v = trivialStorage.load();
293  T t;
294  std::memcpy(&t, &v, sizeof(T));
295  return t;
296  }
folly::std T
template<class T>
const T& folly::settings::detail::SettingCore< T >::getImpl ( std::false_type  ,
std::atomic< uint64_t > &   
) const
inline

Non-SmallPOD version: read the thread local shared_ptr

Definition at line 301 of file SettingsImpl.h.

302  {
303  return const_cast<SettingCore*>(this)->tlValue()->value;
304  }
SettingCore(SettingMetadata meta, T defaultValue, std::atomic< uint64_t > &trivialStorage)
Definition: SettingsImpl.h:334
FOLLY_ALWAYS_INLINE const std::shared_ptr< Contents > & tlValue() const
Definition: SettingsImpl.h:365
template<class T>
const SettingContents<T>& folly::settings::detail::SettingCore< T >::getSlow ( ) const
inline

Definition at line 285 of file SettingsImpl.h.

285  {
286  return *tlValue();
287  }
FOLLY_ALWAYS_INLINE const std::shared_ptr< Contents > & tlValue() const
Definition: SettingsImpl.h:365
template<class T>
std::conditional_t<IsSmallPOD<T>::value, T, const T&> folly::settings::detail::SettingCore< T >::getWithHint ( std::atomic< uint64_t > &  trivialStorage) const
inline
Parameters
trivialStoragemust refer to the same location as the internal trivialStorage_. This hint will generate better inlined code since the address is known at compile time at the callsite.

Definition at line 281 of file SettingsImpl.h.

282  {
283  return getImpl(IsSmallPOD<T>(), trivialStorage);
284  }
T getImpl(std::true_type, std::atomic< uint64_t > &trivialStorage) const
Definition: SettingsImpl.h:291
template<class T>
const SettingMetadata& folly::settings::detail::SettingCore< T >::meta ( ) const
inlineoverride

Definition at line 271 of file SettingsImpl.h.

271  {
272  return meta_;
273  }
template<class T>
void folly::settings::detail::SettingCore< T >::resetToDefault ( SnapshotBase *  snapshot)
inlineoverride

Definition at line 267 of file SettingsImpl.h.

267  {
268  set(defaultValue_, "default", snapshot);
269  }
template<class T>
void folly::settings::detail::SettingCore< T >::set ( const T t,
StringPiece  reason,
SnapshotBase *  snapshot = nullptr 
)
inline

Definition at line 306 of file SettingsImpl.h.

References getKey(), folly::settings::detail::nextGlobalVersion(), folly::settings::detail::saveValueForOutstandingSnapshots(), folly::settings::detail::SettingCore< T >::set(), folly::pushmi::detail::t, uint64_t, and value.

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

306  {
307  /* Check that we can still display it (will throw otherwise) */
308  to<std::string>(t);
309 
310  if (snapshot) {
311  snapshot->set(*this, t, reason);
312  return;
313  }
314 
315  SharedMutex::WriteHolder lg(globalLock_);
316 
317  if (globalValue_) {
319  getKey(), *settingVersion_, BoxedValue(*globalValue_));
320  }
321  globalValue_ = std::make_shared<Contents>(reason.str(), t);
322  if (IsSmallPOD<T>::value) {
323  uint64_t v = 0;
324  std::memcpy(&v, &t, sizeof(T));
325  trivialStorage_.store(v);
326  }
328  }
SettingCoreBase::Version nextGlobalVersion()
Definition: Settings.cpp:125
CachelinePadded< std::atomic< Version > > settingVersion_
Definition: SettingsImpl.h:360
folly::std T
std::atomic< uint64_t > & trivialStorage_
Definition: SettingsImpl.h:356
void saveValueForOutstandingSnapshots(SettingCoreBase::Key settingKey, SettingCoreBase::Version version, const BoxedValue &value)
Definition: Settings.cpp:129
static const char *const value
Definition: Conv.cpp:50
TrafficKey getKey()
std::shared_ptr< Contents > globalValue_
Definition: SettingsImpl.h:354
template<class T>
void folly::settings::detail::SettingCore< T >::setFromString ( StringPiece  newValue,
StringPiece  reason,
SnapshotBase *  snapshot 
)
inlineoverride

Definition at line 253 of file SettingsImpl.h.

References folly::Range< Iter >::str().

256  {
257  set(convertOrConstruct<T>(newValue), reason.str(), snapshot);
258  }
template<class T>
FOLLY_ALWAYS_INLINE const std::shared_ptr<Contents>& folly::settings::detail::SettingCore< T >::tlValue ( ) const
inlineprivate

Definition at line 365 of file SettingsImpl.h.

References LIKELY, and folly::value().

365  {
366  auto& value = **localValue_;
367  if (LIKELY(value.first == *settingVersion_)) {
368  return value.second;
369  }
370  return tlValueSlow();
371  }
#define LIKELY(x)
Definition: Likely.h:47
CachelinePadded< std::atomic< Version > > settingVersion_
Definition: SettingsImpl.h:360
ThreadLocal< CachelinePadded< std::pair< Version, std::shared_ptr< Contents > > > > localValue_
Definition: SettingsImpl.h:363
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
FOLLY_NOINLINE const std::shared_ptr< Contents > & tlValueSlow() const
Definition: SettingsImpl.h:372
template<class T>
FOLLY_NOINLINE const std::shared_ptr<Contents>& folly::settings::detail::SettingCore< T >::tlValueSlow ( ) const
inlineprivate

Definition at line 372 of file SettingsImpl.h.

References folly::value().

372  {
373  auto& value = **localValue_;
374  while (value.first < *settingVersion_) {
375  /* If this destroys the old value, do it without holding the lock */
376  value.second.reset();
377  SharedMutex::ReadHolder lg(globalLock_);
378  value.first = *settingVersion_;
379  value.second = globalValue_;
380  }
381  return value.second;
382  }
CachelinePadded< std::atomic< Version > > settingVersion_
Definition: SettingsImpl.h:360
ThreadLocal< CachelinePadded< std::pair< Version, std::shared_ptr< Contents > > > > localValue_
Definition: SettingsImpl.h:363
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
std::shared_ptr< Contents > globalValue_
Definition: SettingsImpl.h:354

Member Data Documentation

template<class T>
const T folly::settings::detail::SettingCore< T >::defaultValue_
private

Definition at line 351 of file SettingsImpl.h.

template<class T>
SharedMutex folly::settings::detail::SettingCore< T >::globalLock_
private

Definition at line 353 of file SettingsImpl.h.

template<class T>
std::shared_ptr<Contents> folly::settings::detail::SettingCore< T >::globalValue_
private

Definition at line 354 of file SettingsImpl.h.

template<class T>
ThreadLocal<CachelinePadded<std::pair<Version, std::shared_ptr<Contents> > > > folly::settings::detail::SettingCore< T >::localValue_
private

Definition at line 363 of file SettingsImpl.h.

template<class T>
SettingMetadata folly::settings::detail::SettingCore< T >::meta_
private

Definition at line 350 of file SettingsImpl.h.

template<class T>
CachelinePadded<std::atomic<Version> > folly::settings::detail::SettingCore< T >::settingVersion_ {1}
private

Definition at line 360 of file SettingsImpl.h.

template<class T>
std::atomic<uint64_t>& folly::settings::detail::SettingCore< T >::trivialStorage_
private

Definition at line 356 of file SettingsImpl.h.


The documentation for this class was generated from the following file: