Bug 926681 - Make JSRuntime::currentThreadOwnsOperationCallbackLock() work the the same in non-threadsafe builds r=bhackett

This commit is contained in:
Jon Coppeard 2013-10-17 09:41:27 +01:00
parent b5cb5864c1
commit 5290af20fc
2 changed files with 16 additions and 11 deletions

View File

@ -118,6 +118,8 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
#ifdef JS_THREADSAFE
operationCallbackLock(nullptr),
operationCallbackOwner(nullptr),
#else
operationCallbackLockTaken(false),
#endif
#ifdef JS_WORKER_THREADS
workerThreadState(nullptr),

View File

@ -719,38 +719,41 @@ struct JSRuntime : public JS::shadow::Runtime,
/* Branch callback */
JSOperationCallback operationCallback;
#ifdef JS_THREADSAFE
private:
/*
* Lock taken when triggering the operation callback from another thread.
* Protects all data that is touched in this process.
*/
#ifdef JS_THREADSAFE
PRLock *operationCallbackLock;
PRThread *operationCallbackOwner;
public:
#else
bool operationCallbackLockTaken;
#endif // JS_THREADSAFE
public:
class AutoLockForOperationCallback {
#ifdef JS_THREADSAFE
JSRuntime *rt;
public:
AutoLockForOperationCallback(JSRuntime *rt MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : rt(rt) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
JS_ASSERT(!rt->currentThreadOwnsOperationCallbackLock());
#ifdef JS_THREADSAFE
PR_Lock(rt->operationCallbackLock);
rt->operationCallbackOwner = PR_GetCurrentThread();
#else
rt->operationCallbackLockTaken = true;
#endif // JS_THREADSAFE
}
~AutoLockForOperationCallback() {
JS_ASSERT(rt->operationCallbackOwner == PR_GetCurrentThread());
JS_ASSERT(rt->currentThreadOwnsOperationCallbackLock());
#ifdef JS_THREADSAFE
rt->operationCallbackOwner = nullptr;
PR_Unlock(rt->operationCallbackLock);
}
#else // JS_THREADSAFE
public:
AutoLockForOperationCallback(JSRuntime *rt MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
#else
rt->operationCallbackLockTaken = false;
#endif // JS_THREADSAFE
}
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
@ -759,7 +762,7 @@ struct JSRuntime : public JS::shadow::Runtime,
#if defined(JS_THREADSAFE)
return operationCallbackOwner == PR_GetCurrentThread();
#else
return true;
return operationCallbackLockTaken;
#endif
}