Make using folly::Singleton easier: names and direct referencing
authorChip Turner <chip@fb.com>
Wed, 30 Jul 2014 22:38:28 +0000 (15:38 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Sep 2014 21:22:23 +0000 (14:22 -0700)
commit95f17b5283ce53886181d6315b1945149696f7eb
treee4df2d310f596453b8efaf23069328e8d6785429
parenta9bfb17955960ed3a93eaeb3d12a74ac1af7d8c7
Make using folly::Singleton easier: names and direct referencing

Summary:
There are times when you want multiple singletons of the same
underlying type -- for instance, a fast and slow request handling
singleton.  This diff allows for that with an optional name that
disambiguates multiple singletons of the same type.

In addition, we now also allow direct dereferencing of the
Singleton<Foo> object to get to the underlying singleton.  This is most
useful in cases where a singleton is used inside of the same cpp file it
is defined.

Finally, make get() faster by caching the underlying pointer rather than
accessing the shared pointer.  If you're using it, you already have a
race condition and hopefully your singleton lifecycle is sane and safe
from problems this may cause.

Test Plan: runtests

Reviewed By: hans@fb.com

Subscribers: njormrod, lins, anca

FB internal diff: D1485887
folly/experimental/Singleton.h
folly/experimental/test/SingletonTest.cpp