From f8b4c978673cb7e618d5a53bc49d3b49324ff9b5 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 22 Mar 2017 12:04:21 -0600 Subject: [PATCH] Bug 1348419 - Use thread_local on XP_WIN and XP_MACOSX; r=froydnj MozReview-Commit-ID: 75dTUk27p94 --HG-- extra : rebase_source : f93d5b063a6ff14d8eb6f5236828450f3f784b8c --- js/src/jsutil.cpp | 2 +- mfbt/ThreadLocal.h | 38 ++++++-------------------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/js/src/jsutil.cpp b/js/src/jsutil.cpp index 86b72cc9b8f1..709846734b20 100644 --- a/js/src/jsutil.cpp +++ b/js/src/jsutil.cpp @@ -39,7 +39,7 @@ mozilla::Atomic AutoEnterOOMUnsafeRegion::owner_; namespace oom { JS_PUBLIC_DATA(uint32_t) targetThread = 0; -JS_PUBLIC_DATA(MOZ_THREAD_LOCAL(uint32_t)) threadType; +MOZ_THREAD_LOCAL(uint32_t) threadType; JS_PUBLIC_DATA(uint64_t) maxAllocations = UINT64_MAX; JS_PUBLIC_DATA(uint64_t) counter = 0; JS_PUBLIC_DATA(bool) failAlways = true; diff --git a/mfbt/ThreadLocal.h b/mfbt/ThreadLocal.h index 880e677357db..391e748ada22 100644 --- a/mfbt/ThreadLocal.h +++ b/mfbt/ThreadLocal.h @@ -9,20 +9,7 @@ #ifndef mozilla_ThreadLocal_h #define mozilla_ThreadLocal_h -#if defined(XP_WIN) -// This file will get included in any file that wants to add a profiler mark. -// In order to not bring together we could include windef.h and -// winbase.h which are sufficient to get the prototypes for the Tls* functions. -// # include -// # include -// Unfortunately, even including these headers causes us to add a bunch of ugly -// stuff to our namespace e.g #define CreateEvent CreateEventW -extern "C" { -__declspec(dllimport) void* __stdcall TlsGetValue(unsigned long); -__declspec(dllimport) int __stdcall TlsSetValue(unsigned long, void*); -__declspec(dllimport) unsigned long __stdcall TlsAlloc(); -} -#else +#if !defined(XP_WIN) # include # include #endif @@ -44,7 +31,7 @@ typedef sig_atomic_t sig_safe_t; namespace detail { -#if defined(HAVE_THREAD_TLS_KEYWORD) +#if defined(HAVE_THREAD_TLS_KEYWORD) || defined(XP_WIN) || defined(XP_MACOSX) #define MOZ_HAS_THREAD_LOCAL #endif @@ -91,11 +78,7 @@ template class ThreadLocal { #ifndef MOZ_HAS_THREAD_LOCAL -#if defined(XP_WIN) - typedef unsigned long key_t; -#else typedef pthread_key_t key_t; -#endif // Integral types narrower than void* must be extended to avoid // warnings from valgrind on some platforms. This helper type @@ -161,12 +144,7 @@ ThreadLocal::init() return true; #else if (!initialized()) { -#ifdef XP_WIN - mKey = TlsAlloc(); - mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES -#else mInited = !pthread_key_create(&mKey, nullptr); -#endif } return mInited; #endif @@ -181,11 +159,7 @@ ThreadLocal::get() const #else MOZ_ASSERT(initialized()); void* h; -#ifdef XP_WIN - h = TlsGetValue(mKey); -#else h = pthread_getspecific(mKey); -#endif return static_cast(reinterpret_cast::Type>(h)); #endif } @@ -199,11 +173,7 @@ ThreadLocal::set(const T aValue) #else MOZ_ASSERT(initialized()); void* h = reinterpret_cast(static_cast::Type>(aValue)); -#ifdef XP_WIN - bool succeeded = TlsSetValue(mKey, h); -#else bool succeeded = !pthread_setspecific(mKey, h); -#endif if (!succeeded) { MOZ_CRASH(); } @@ -211,7 +181,11 @@ ThreadLocal::set(const T aValue) } #ifdef MOZ_HAS_THREAD_LOCAL +#if defined(XP_WIN) || defined(XP_MACOSX) +#define MOZ_THREAD_LOCAL(TYPE) thread_local mozilla::detail::ThreadLocal +#else #define MOZ_THREAD_LOCAL(TYPE) __thread mozilla::detail::ThreadLocal +#endif #else #define MOZ_THREAD_LOCAL(TYPE) mozilla::detail::ThreadLocal #endif