diff --git a/mozilla/xpcom/base/nsDebug.cpp b/mozilla/xpcom/base/nsDebug.cpp index 76408c92c02..693f5bf1e65 100644 --- a/mozilla/xpcom/base/nsDebug.cpp +++ b/mozilla/xpcom/base/nsDebug.cpp @@ -340,6 +340,7 @@ NS_ErrorAccordingToNSPR() #include "prthread.h" extern "C" NS_EXPORT void* NS_CurrentThread(void); +extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, const char* msg); void* NS_CurrentThread(void) @@ -348,6 +349,29 @@ NS_CurrentThread(void) return th; } +/* + * DON'T TOUCH THAT DIAL... + * For now, we're making the thread-safety checking be on by default which, yes, slows + * down linux a bit... but we're doing it so that everybody has a chance to exercise + * their code a good deal before the beta. After we branch, we'll turn this back off + * and then you can enable it explicitly by setting XPCOM_CHECK_THREADSAFE. This will + * let you verify the thread-safety of your classes without impacting everyone all the + * time. + */ +static PRBool gCheckThreadSafeDefault = PR_TRUE; // READ THE ABOVE COMMENT FIRST! + +void +NS_CheckThreadSafe(void* owningThread, const char* msg) +{ + static int check = -1; + if (check == -1) { + check = gCheckThreadSafeDefault || getenv("XPCOM_CHECK_THREADSAFE") != 0; + } + if (check) { + NS_ASSERTION(owningThread == NS_CurrentThread(), msg); + } +} + #endif // NS_DEBUG //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/base/nsISupportsUtils.h b/mozilla/xpcom/base/nsISupportsUtils.h index afc92d0e5f8..d3bda882e84 100644 --- a/mozilla/xpcom/base/nsISupportsUtils.h +++ b/mozilla/xpcom/base/nsISupportsUtils.h @@ -142,19 +142,19 @@ public: #if defined(NS_DEBUG) && defined(NS_MT_SUPPORTED) extern "C" NS_EXPORT void* NS_CurrentThread(void); +extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, const char* msg); -#define NS_DECL_OWNINGTHREAD void* _mOwningThread; -#define NS_IMPL_OWNINGTHREAD() (_mOwningThread = NS_CurrentThread()) -#define NS_ASSERT_OWNINGTHREAD(_class) \ - NS_ASSERTION(_mOwningThread == NS_CurrentThread(), #_class " not thread-safe"); +#define NS_DECL_OWNINGTHREAD void* _mOwningThread; +#define NS_IMPL_OWNINGTHREAD() (_mOwningThread = NS_CurrentThread()) +#define NS_ASSERT_OWNINGTHREAD(_class) NS_CheckThreadSafe(_mOwningThread, #_class " not thread-safe") -#else // !(defined(NS_DEBUG) && !defined(NS_MT_SUPPORTED)) +#else // !(defined(NS_DEBUG) && defined(NS_MT_SUPPORTED)) -#define NS_DECL_OWNINGTHREAD /* nothing */ -#define NS_IMPL_OWNINGTHREAD() ((void)0) -#define NS_ASSERT_OWNINGTHREAD(_class) ((void)0) +#define NS_DECL_OWNINGTHREAD /* nothing */ +#define NS_IMPL_OWNINGTHREAD() ((void)0) +#define NS_ASSERT_OWNINGTHREAD(_class) ((void)0) -#endif // !(defined(NS_DEBUG) && !defined(NS_MT_SUPPORTED)) +#endif // !(defined(NS_DEBUG) && defined(NS_MT_SUPPORTED)) //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/build/dlldeps.cpp b/mozilla/xpcom/build/dlldeps.cpp index 48e05c4d146..fd673fc7655 100644 --- a/mozilla/xpcom/build/dlldeps.cpp +++ b/mozilla/xpcom/build/dlldeps.cpp @@ -61,7 +61,6 @@ #include "nsIInterfaceRequestor.h" #ifdef DEBUG #include "pure.h" -extern "C" NS_EXPORT void* NS_CurrentThread(void); #endif class dummyComparitor: public nsAVLNodeComparitor { @@ -127,7 +126,6 @@ void XXXNeverCalled() nsCOMPtr dummyFoo(do_GetInterface(nsnull)); #ifdef DEBUG TestSegmentedBuffer(); - NS_CurrentThread(); #endif NS_NewSizeOfHandler(0); nsStorageStream(); diff --git a/mozilla/xpcom/glue/nsDebug.cpp b/mozilla/xpcom/glue/nsDebug.cpp index 76408c92c02..693f5bf1e65 100644 --- a/mozilla/xpcom/glue/nsDebug.cpp +++ b/mozilla/xpcom/glue/nsDebug.cpp @@ -340,6 +340,7 @@ NS_ErrorAccordingToNSPR() #include "prthread.h" extern "C" NS_EXPORT void* NS_CurrentThread(void); +extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, const char* msg); void* NS_CurrentThread(void) @@ -348,6 +349,29 @@ NS_CurrentThread(void) return th; } +/* + * DON'T TOUCH THAT DIAL... + * For now, we're making the thread-safety checking be on by default which, yes, slows + * down linux a bit... but we're doing it so that everybody has a chance to exercise + * their code a good deal before the beta. After we branch, we'll turn this back off + * and then you can enable it explicitly by setting XPCOM_CHECK_THREADSAFE. This will + * let you verify the thread-safety of your classes without impacting everyone all the + * time. + */ +static PRBool gCheckThreadSafeDefault = PR_TRUE; // READ THE ABOVE COMMENT FIRST! + +void +NS_CheckThreadSafe(void* owningThread, const char* msg) +{ + static int check = -1; + if (check == -1) { + check = gCheckThreadSafeDefault || getenv("XPCOM_CHECK_THREADSAFE") != 0; + } + if (check) { + NS_ASSERTION(owningThread == NS_CurrentThread(), msg); + } +} + #endif // NS_DEBUG //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/glue/nsISupportsUtils.h b/mozilla/xpcom/glue/nsISupportsUtils.h index afc92d0e5f8..d3bda882e84 100644 --- a/mozilla/xpcom/glue/nsISupportsUtils.h +++ b/mozilla/xpcom/glue/nsISupportsUtils.h @@ -142,19 +142,19 @@ public: #if defined(NS_DEBUG) && defined(NS_MT_SUPPORTED) extern "C" NS_EXPORT void* NS_CurrentThread(void); +extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, const char* msg); -#define NS_DECL_OWNINGTHREAD void* _mOwningThread; -#define NS_IMPL_OWNINGTHREAD() (_mOwningThread = NS_CurrentThread()) -#define NS_ASSERT_OWNINGTHREAD(_class) \ - NS_ASSERTION(_mOwningThread == NS_CurrentThread(), #_class " not thread-safe"); +#define NS_DECL_OWNINGTHREAD void* _mOwningThread; +#define NS_IMPL_OWNINGTHREAD() (_mOwningThread = NS_CurrentThread()) +#define NS_ASSERT_OWNINGTHREAD(_class) NS_CheckThreadSafe(_mOwningThread, #_class " not thread-safe") -#else // !(defined(NS_DEBUG) && !defined(NS_MT_SUPPORTED)) +#else // !(defined(NS_DEBUG) && defined(NS_MT_SUPPORTED)) -#define NS_DECL_OWNINGTHREAD /* nothing */ -#define NS_IMPL_OWNINGTHREAD() ((void)0) -#define NS_ASSERT_OWNINGTHREAD(_class) ((void)0) +#define NS_DECL_OWNINGTHREAD /* nothing */ +#define NS_IMPL_OWNINGTHREAD() ((void)0) +#define NS_ASSERT_OWNINGTHREAD(_class) ((void)0) -#endif // !(defined(NS_DEBUG) && !defined(NS_MT_SUPPORTED)) +#endif // !(defined(NS_DEBUG) && defined(NS_MT_SUPPORTED)) //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/macbuild/xpcomDebug.exp b/mozilla/xpcom/macbuild/xpcomDebug.exp index 29c1bb24f14..d370d41bec9 100644 --- a/mozilla/xpcom/macbuild/xpcomDebug.exp +++ b/mozilla/xpcom/macbuild/xpcomDebug.exp @@ -1,3 +1,4 @@ # These are now just additions for the debug build. PL_VectorAssertValid NS_CurrentThread +NS_CheckThreadSafe