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