Fix folly::Singleton to work in dynamically linked binaries
authorAndrii Grynenko <andrii@fb.com>
Fri, 19 Feb 2016 19:02:35 +0000 (11:02 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Fri, 19 Feb 2016 19:20:31 +0000 (11:20 -0800)
commitf390a90d567a2abe56fecca39ca880a998cbe24a
treee192aa6e4932fd2e2a9c220e41e8b13c1d603c45
parentac31e5f5e80027418cb06a7718b6ade3cacad8bc
Fix folly::Singleton to work in dynamically linked binaries

Summary:This implements StaticSingletonManager which is then used to create all leaked Meyers singletons.

StaticSingletonManager is a singleton itself, which is created in a separate compilation unit (Singleton.cpp) and so we can be sure that other compilation units will always see a single instance of StaticSingletonManager, even if linked dynamically.

StaticSingletonManager then keeps a dictionary of typeid -> object pointer, which is used to de-duplicate same singleton being re-created from different compilation units (linked dynamically), usually because of code inlining.

override-unit-failures

Reviewed By: yfeldblum

Differential Revision: D2913027

fb-gh-sync-id: 1f5015a79a7a8297ebf5f0fe3fd0cc7eb44f706b
shipit-source-id: 1f5015a79a7a8297ebf5f0fe3fd0cc7eb44f706b
folly/Singleton-inl.h
folly/Singleton.cpp
folly/Singleton.h