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

git-svn-id: svn://10.0.0.236/trunk@62390 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
warren%netscape.com
2000-03-08 09:21:32 +00:00
parent 55b0054293
commit 84f531a52e
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
////////////////////////////////////////////////////////////////////////////////