From f085e09f42f488fbecd042f1bd5a84b13096f31f Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 15 Jan 2012 09:13:07 +0100 Subject: [PATCH] Bug 677079 - Part a: Move AutoLockGC to jsfriendapi.h; r=igor --- js/src/jscntxt.h | 32 -------------------------------- js/src/jsfriendapi.cpp | 25 +++++++++++++++++++++++++ js/src/jsfriendapi.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 32 deletions(-) diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 12ce1e83bef3..b47c0a403f9a 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -1617,38 +1617,6 @@ class AutoXMLRooter : private AutoGCRooter { }; #endif /* JS_HAS_XML_SUPPORT */ -class AutoLockGC { - public: - explicit AutoLockGC(JSRuntime *rt = NULL - JS_GUARD_OBJECT_NOTIFIER_PARAM) - : runtime(rt) - { - JS_GUARD_OBJECT_NOTIFIER_INIT; - if (rt) - JS_LOCK_GC(rt); - } - - bool locked() const { - return !!runtime; - } - - void lock(JSRuntime *rt) { - JS_ASSERT(rt); - JS_ASSERT(!runtime); - runtime = rt; - JS_LOCK_GC(rt); - } - - ~AutoLockGC() { - if (runtime) - JS_UNLOCK_GC(runtime); - } - - private: - JSRuntime *runtime; - JS_DECL_USE_GUARD_OBJECT_NOTIFIER -}; - class AutoUnlockGC { private: JSRuntime *rt; diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index dbe9644d71e3..9da629bd80ca 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -43,6 +43,8 @@ #include "jswrapper.h" #include "jsweakmap.h" +#include "mozilla/GuardObjects.h" + #include "jsobjinlines.h" using namespace js; @@ -467,6 +469,29 @@ js::DumpHeapComplete(JSContext *cx, FILE *fp) namespace js { +/* static */ void +AutoLockGC::LockGC(JSRuntime *rt) +{ + JS_ASSERT(rt); + JS_LOCK_GC(rt); +} + +/* static */ void +AutoLockGC::UnlockGC(JSRuntime *rt) +{ + JS_ASSERT(rt); + JS_UNLOCK_GC(rt); +} + +void +AutoLockGC::lock(JSRuntime *rt) +{ + JS_ASSERT(rt); + JS_ASSERT(!runtime); + runtime = rt; + JS_LOCK_GC(rt); +} + #ifdef JS_THREADSAFE JSThread * GetContextThread(const JSContext *cx) diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 6bd09cb4d928..d046a52d45fd 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -44,6 +44,8 @@ #include "jspubtd.h" #include "jsprvtd.h" +#include "mozilla/GuardObjects.h" + JS_BEGIN_EXTERN_C extern JS_FRIEND_API(void) @@ -453,6 +455,37 @@ JS_FRIEND_API(JSThread *) GetContextThread(const JSContext *cx); #endif +class JS_FRIEND_API(AutoLockGC) +{ + public: + explicit AutoLockGC(JSRuntime *rt = NULL + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : runtime(rt) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + if (rt) + LockGC(rt); + } + + ~AutoLockGC() + { + if (runtime) + UnlockGC(runtime); + } + + bool locked() const { + return !!runtime; + } + void lock(JSRuntime *rt); + + private: + static void LockGC(JSRuntime *rt); + static void UnlockGC(JSRuntime *rt); + + JSRuntime *runtime; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + } /* namespace js */ /*