Permalink
Browse files

Bug 756709 - Make ThreadLocal::set crash on failure (which really can…

… only happen if per-thread memory for the TLS entry couldn't be allocated, which should be really rare). r=Ms2ger

--HG--
extra : rebase_source : ecda463195c9b67ef6b7d02ef32ed0aa56bc11bc
  • Loading branch information...
1 parent 6cd8a83 commit 17d6447e5466e7d3f66bc2c6ae24c25063c4c08f @jswalden jswalden committed Dec 17, 2012
Showing with 13 additions and 10 deletions.
  1. +13 −10 mfbt/ThreadLocal.h
View
@@ -5,8 +5,8 @@
/* Cross-platform lightweight thread local data wrappers. */
-#ifndef mozilla_TLS_h_
-#define mozilla_TLS_h_
+#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.
@@ -17,8 +17,8 @@
// 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) void* __stdcall TlsGetValue(unsigned long);
+__declspec(dllimport) int __stdcall TlsSetValue(unsigned long, void*);
__declspec(dllimport) unsigned long __stdcall TlsAlloc();
}
#else
@@ -83,7 +83,7 @@ class ThreadLocal
inline T get() const;
- inline bool set(const T value);
+ inline void set(const T value);
bool initialized() const {
return inited;
@@ -98,7 +98,7 @@ template<typename T>
inline bool
ThreadLocal<T>::init()
{
- MOZ_STATIC_ASSERT(sizeof(T) <= sizeof(void *),
+ MOZ_STATIC_ASSERT(sizeof(T) <= sizeof(void*),
"mozilla::ThreadLocal can't be used for types larger than "
"a pointer");
MOZ_ASSERT(!initialized());
@@ -126,19 +126,22 @@ ThreadLocal<T>::get() const
}
template<typename T>
-inline bool
+inline void
ThreadLocal<T>::set(const T value)
{
MOZ_ASSERT(initialized());
Helper h;
h.value = value;
+ bool succeeded;
#ifdef XP_WIN
- return TlsSetValue(key, h.ptr);
+ succeeded = TlsSetValue(key, h.ptr);
#else
- return !pthread_setspecific(key, h.ptr);
+ succeeded = !pthread_setspecific(key, h.ptr);
#endif
+ if (!succeeded)
+ MOZ_CRASH();
}
} // namespace mozilla
-#endif // mozilla_TLS_h_
+#endif // mozilla_ThreadLocal_h_

0 comments on commit 17d6447

Please sign in to comment.