Made the thread-safety checking able to be turned on/off by the XPCOM_CHECK_THREADSAFE env var. a=jar,r=mscott

This commit is contained in:
warren%netscape.com 2000-03-08 09:21:32 +00:00
parent 242a3bb70c
commit 84ea15d65a
6 changed files with 67 additions and 20 deletions

View File

@ -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
////////////////////////////////////////////////////////////////////////////////

View File

@ -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))
////////////////////////////////////////////////////////////////////////////////

View File

@ -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<nsISupports> dummyFoo(do_GetInterface(nsnull));
#ifdef DEBUG
TestSegmentedBuffer();
NS_CurrentThread();
#endif
NS_NewSizeOfHandler(0);
nsStorageStream();

View File

@ -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
////////////////////////////////////////////////////////////////////////////////

View File

@ -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))
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,3 +1,4 @@
# These are now just additions for the debug build.
PL_VectorAssertValid
NS_CurrentThread
NS_CheckThreadSafe