Bug 714458 - Part b: Provide the thread-related APIs xpcprivate.h needs; r=igor

This introduces a JS_GetCurrentThread to go with the existing
JS_GetContextThread, as well as a js::GetContextThread to get at the actual
JSThread object, and inlines the only use of JS_THREAD_ID.
This commit is contained in:
Ms2ger 2012-01-11 09:23:07 +01:00
parent 38fbde8026
commit fab1325ed4
8 changed files with 32 additions and 10 deletions

View File

@ -6587,6 +6587,12 @@ JS_ThrowStopIteration(JSContext *cx)
return js_ThrowStopIteration(cx);
}
JS_PUBLIC_API(intptr_t)
JS_GetCurrentThread()
{
return reinterpret_cast<intptr_t>(js_CurrentThreadId());
}
/*
* Get the owning thread id of a context. Returns 0 if the context is not
* owned by any thread.
@ -6595,7 +6601,7 @@ JS_PUBLIC_API(intptr_t)
JS_GetContextThread(JSContext *cx)
{
#ifdef JS_THREADSAFE
return reinterpret_cast<intptr_t>(JS_THREAD_ID(cx));
return cx->thread() ? reinterpret_cast<intptr_t>(cx->thread()->id) : 0;
#else
return 0;
#endif

View File

@ -4929,6 +4929,9 @@ JS_ThrowReportedError(JSContext *cx, const char *message,
extern JS_PUBLIC_API(JSBool)
JS_ThrowStopIteration(JSContext *cx);
extern JS_PUBLIC_API(intptr_t)
JS_GetCurrentThread();
/*
* Associate the current thread with the given context. This is done
* implicitly by JS_NewContext.

View File

@ -1310,10 +1310,6 @@ struct JSContext
namespace js {
#ifdef JS_THREADSAFE
# define JS_THREAD_ID(cx) ((cx)->thread() ? (cx)->thread()->id : 0)
#endif
#if defined JS_THREADSAFE && defined DEBUG
class AutoCheckRequestDepth {

View File

@ -458,3 +458,15 @@ js::DumpHeapComplete(JSContext *cx, FILE *fp)
}
#endif
namespace js {
#ifdef JS_THREADSAFE
JSThread *
GetContextThread(const JSContext *cx)
{
return cx->thread();
}
#endif
} // namespace js

View File

@ -445,6 +445,11 @@ GetPCCountScriptSummary(JSContext *cx, size_t script);
JS_FRIEND_API(JSString *)
GetPCCountScriptContents(JSContext *cx, size_t script);
#ifdef JS_THREADSAFE
JS_FRIEND_API(JSThread *)
GetContextThread(const JSContext *cx);
#endif
} /* namespace js */
/*

View File

@ -423,7 +423,7 @@ XPCPerThreadData::GetDataImpl(JSContext *cx)
}
if (cx && !sMainJSThread && NS_IsMainThread()) {
sMainJSThread = cx->thread();
sMainJSThread = js::GetContextThread(cx);
sMainThreadData = data;

View File

@ -552,7 +552,7 @@ GetContextFromObject(JSObject *obj)
if (xpcc) {
JSContext *cx = xpcc->GetJSContext();
if (cx->thread()->id == js_CurrentThreadId())
if (JS_GetContextThread(cx) == JS_GetCurrentThread())
return cx;
}

View File

@ -3646,9 +3646,9 @@ public:
static inline XPCPerThreadData* GetData(JSContext *cx)
{
if (cx) {
NS_ASSERTION(cx->thread(), "Uh, JS context w/o a thread?");
NS_ASSERTION(js::GetContextThread(cx), "Uh, JS context w/o a thread?");
if (cx->thread() == sMainJSThread)
if (js::GetContextThread(cx) == sMainJSThread)
return sMainThreadData;
} else if (sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread()) {
return sMainThreadData;
@ -3751,7 +3751,7 @@ public:
{sMainJSThread = nsnull; sMainThreadData = nsnull;}
static bool IsMainThread(JSContext *cx)
{ return cx->thread() == sMainJSThread; }
{ return js::GetContextThread(cx) == sMainJSThread; }
private:
XPCPerThreadData();