From b0005c7d689122fcb36a2cbf4c666cde4fbc5d44 Mon Sep 17 00:00:00 2001 From: Ben Maurer Date: Tue, 13 Oct 2015 09:08:02 -0700 Subject: [PATCH] Fix ThreadLocal on android/apple MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; -- 2.34.1