Fix ThreadLocal on android/apple
authorBen Maurer <bmaurer@fb.com>
Tue, 13 Oct 2015 16:08:02 +0000 (09:08 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Tue, 13 Oct 2015 16:20:14 +0000 (09:20 -0700)
Summary: The thread local destructor was assuming that the singleton object
had been created.

Reviewed By: @​yangchi

Differential Revision: D2536166

fb-gh-sync-id: b0c08e0990f684c0afae054ee17c62a924260f2b

folly/detail/ThreadLocalDetail.h

index d3d62ad84c674533b34a2932388c21c4832ecc8f..6302be42415ed5aed6ac3d80d32c1d6c0f9806a9 100644 (file)
@@ -275,11 +275,12 @@ struct StaticMeta {
 #ifdef FOLLY_TLD_USE_FOLLY_TLS
     return &threadEntry_;
 #else
+    auto key = instance().pthreadKey_;
     ThreadEntry* threadEntry =
-        static_cast<ThreadEntry*>(pthread_getspecific(inst_->pthreadKey_));
+      static_cast<ThreadEntry*>(pthread_getspecific(key));
     if (!threadEntry) {
         threadEntry = new ThreadEntry();
-        int ret = pthread_setspecific(inst_->pthreadKey_, threadEntry);
+        int ret = pthread_setspecific(key, threadEntry);
         checkPosixError(ret, "pthread_setspecific failed");
     }
     return threadEntry;