proxygen
SingletonThreadLocal.h File Reference
#include <boost/intrusive/list.hpp>
#include <folly/ScopeGuard.h>
#include <folly/ThreadLocal.h>
#include <folly/detail/Singleton.h>
#include <folly/functional/Invoke.h>

Go to the source code of this file.

Classes

class  folly::SingletonThreadLocal< T, Tag, Make, TLTag >
 
struct  folly::SingletonThreadLocal< T, Tag, Make, TLTag >::Node
 
struct  folly::SingletonThreadLocal< T, Tag, Make, TLTag >::Wrapper
 

Namespaces

 folly
 —— Concurrent Priority Queue Implementation ——
 

Macros

#define FOLLY_DECLARE_REUSED(name, ...)
 

Macro Definition Documentation

#define FOLLY_DECLARE_REUSED (   name,
  ... 
)
Value:
struct __folly_reused_type_##name { \
__VA_ARGS__ object; \
}; \
auto& name = \
auto __folly_reused_g_##name = ::folly::makeGuard([&] { name.clear(); })
void * object
Definition: AtFork.cpp:32
const char * name
Definition: http_parser.c:437
FOLLY_NODISCARD detail::ScopeGuardImplDecay< F, true > makeGuard(F &&f) noexcept(noexcept(detail::ScopeGuardImplDecay< F, true >(static_cast< F && >(f))))
Definition: ScopeGuard.h:184
FOLLY_EXPORT static FOLLY_ALWAYS_INLINE T & get()

FOLLY_DECLARE_REUSED

Useful for local variables of container types, where it is desired to avoid the overhead associated with the local variable entering and leaving scope. Rather, where it is desired that the memory be reused between invocations of the same scope in the same thread rather than deallocated and reallocated between invocations of the same scope in the same thread. Note that the container will always be cleared between invocations; it is only the backing memory allocation which is reused.

Example:

void traverse_perform(int root); template <typename f>=""> void traverse_each_child_r(int root, F const&); void traverse_depthwise(int root) { // preserves some of the memory backing these per-thread data structures FOLLY_DECLARE_REUSED(seen, std::unordered_set<int>); FOLLY_DECLARE_REUSED(work, std::vector<int>); // example algorithm that uses these per-thread data structures work.push_back(root); while (!work.empty()) { root = work.back(); work.pop_back(); seen.insert(root); traverse_perform(root); traverse_each_child_r(root, [&](int item) { if (!seen.count(item)) { work.push_back(item); } }); } }

Definition at line 205 of file SingletonThreadLocal.h.

Referenced by TEST().