Bug 1390386 - mfbt/ThreadLocal should support pointers-to-const with the pthread impl. - r=froydnj draft
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 14 Aug 2017 17:53:38 -0700
changeset 646250 aead9817daee09d6eb2378b31905eb954587f34b
parent 646249 730222d8b4e8a8a8017bcab697073e40509f5091
child 646945 c7728505f475e7adbd9c33df8d8bd208995a0a37
push id74039
push userbmo:jgilbert@mozilla.com
push dateTue, 15 Aug 2017 01:45:45 +0000
reviewersfroydnj
bugs1390386
milestone57.0a1
Bug 1390386 - mfbt/ThreadLocal should support pointers-to-const with the pthread impl. - r=froydnj reinterpret_cast can't convert const T* to void*. Just use c-style casts. MozReview-Commit-ID: GHtNRRFUsr5
mfbt/ThreadLocal.h
--- a/mfbt/ThreadLocal.h
+++ b/mfbt/ThreadLocal.h
@@ -151,33 +151,32 @@ ThreadLocal<T>::init()
 template<typename T>
 inline T
 ThreadLocal<T>::get() const
 {
 #ifdef MOZ_HAS_THREAD_LOCAL
   return mValue;
 #else
   MOZ_ASSERT(initialized());
-  void* h;
-  h = pthread_getspecific(mKey);
-  return static_cast<T>(reinterpret_cast<typename Helper<T>::Type>(h));
+  void* h = pthread_getspecific(mKey);
+  return static_cast<T>((typename Helper<T>::Type)h);
 #endif
 }
 
 template<typename T>
 inline void
 ThreadLocal<T>::set(const T aValue)
 {
 #ifdef MOZ_HAS_THREAD_LOCAL
   mValue = aValue;
 #else
   MOZ_ASSERT(initialized());
-  void* h = reinterpret_cast<void*>(static_cast<typename Helper<T>::Type>(aValue));
+  void* h = (void*)(static_cast<typename Helper<T>::Type>(aValue));
   bool succeeded = !pthread_setspecific(mKey, h);
-  if (!succeeded) {
+  if (MOZ_UNLIKELY( !succeeded )) {
     MOZ_CRASH();
   }
 #endif
 }
 
 #ifdef MOZ_HAS_THREAD_LOCAL
 #if defined(XP_WIN) || defined(MACOSX_HAS_THREAD_LOCAL)
 #define MOZ_THREAD_LOCAL(TYPE) thread_local mozilla::detail::ThreadLocal<TYPE>