summaryrefslogtreecommitdiffstats
path: root/libutils
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-02-23 14:48:51 -0800
committerColin Cross <ccross@android.com>2017-02-23 18:22:46 -0800
commitb0145091a7a7503178fe47e6bfbe0de03caa4ba0 (patch)
tree7e211f0210cdeb9897dae833e64754ab727ec37a /libutils
parent8d302763aba8a48e3d4a4743933c7b85c659b32f (diff)
downloadcore-b0145091a7a7503178fe47e6bfbe0de03caa4ba0.tar.gz
core-b0145091a7a7503178fe47e6bfbe0de03caa4ba0.tar.bz2
core-b0145091a7a7503178fe47e6bfbe0de03caa4ba0.zip
Fix multiton issue
I385a05a3ca01258e44fe3b37ef77e4aaff547b26 broke Singleton in the same way that 544e3e3606abebd2e5016bdb33a3ed05a1650e5b had already fixed once. Fix it again, the next CL will add tests. This affected cases where two libraries referenced the same singleton, the one that was supposed to define the singleton was already loaded, and then the second library was dlopen'd. Bug: 35674422 Test: out/host/linux-x86/nativetest64/libutils_tests/libutils_tests from later CL Change-Id: I87c64f95ed294a887e67a6c11be3072299789f01
Diffstat (limited to 'libutils')
-rw-r--r--libutils/include/utils/Singleton.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/libutils/include/utils/Singleton.h b/libutils/include/utils/Singleton.h
index 7cc4c18be..a989a4703 100644
--- a/libutils/include/utils/Singleton.h
+++ b/libutils/include/utils/Singleton.h
@@ -26,6 +26,16 @@
namespace android {
// ---------------------------------------------------------------------------
+// Singleton<TYPE> may be used in multiple libraries, only one of which should
+// define the static member variables using ANDROID_SINGLETON_STATIC_INSTANCE.
+// Turn off -Wundefined-var-template so other users don't get:
+// instantiation of variable 'android::Singleton<TYPE>::sLock' required here,
+// but no definition is available
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wundefined-var-template"
+#endif
+
template <typename TYPE>
class ANDROID_API Singleton
{
@@ -56,11 +66,9 @@ private:
static TYPE* sInstance;
};
-template <typename TYPE>
-Mutex Singleton<TYPE>::sLock;
-
-template <typename TYPE>
-TYPE* Singleton<TYPE>::sInstance;
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
/*
* use ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) in your implementation file