From: Ben Maurer Date: Tue, 13 Oct 2015 16:08:02 +0000 (-0700) Subject: Fix ThreadLocal on android/apple X-Git-Tag: deprecate-dynamic-initializer~336 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b0005c7d689122fcb36a2cbf4c666cde4fbc5d44;p=folly.git Fix ThreadLocal on android/apple 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 --- diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index d3d62ad8..6302be42 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -275,11 +275,12 @@ struct StaticMeta { #ifdef FOLLY_TLD_USE_FOLLY_TLS return &threadEntry_; #else + auto key = instance().pthreadKey_; ThreadEntry* threadEntry = - static_cast(pthread_getspecific(inst_->pthreadKey_)); + static_cast(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;