X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSingletonThreadLocal.h;h=692495645d8baf74ec288fc763c47c0e4c8696ab;hb=afde52ff7655ba79759eafdbee14b3fe47428fce;hp=e073fecd2d2f303817fa82daaaec60c945bd5cc4;hpb=fc353ba6b01facad6ec1a8eb55a2e11e1483540c;p=folly.git diff --git a/folly/SingletonThreadLocal.h b/folly/SingletonThreadLocal.h index e073fecd..69249564 100644 --- a/folly/SingletonThreadLocal.h +++ b/folly/SingletonThreadLocal.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,26 @@ #pragma once -#include #include +#include namespace folly { +// SingletonThreadLocal +// +// This class can help you implement a per-thread leaky-singleton model within +// your application. Please read the usage block at the top of Singleton.h as +// the recommendations there are also generally applicable to this class. +// +// When we say this is "leaky" we mean that the T instances held by a +// SingletonThreadLocal will survive until their owning thread exits, +// regardless of the lifetime of the singleton object holding them. That +// means that they can be safely used during process shutdown, and +// that they can also be safely used in an application that spawns many +// temporary threads throughout its life. +// +// Keywords to help people find this class in search: +// Thread Local Singleton ThreadLocalSingleton template class SingletonThreadLocal { public: @@ -38,7 +53,6 @@ class SingletonThreadLocal { static T& get() { #ifdef FOLLY_TLS - *localPtr() = nullptr; if (UNLIKELY(*localPtr() == nullptr)) { *localPtr() = &(**SingletonT::get()); } @@ -78,4 +92,4 @@ class SingletonThreadLocal { SingletonT singleton_; }; -} +} // namespace folly