From 7f766daf0729ffda1f0a35bafede8e5d1b8c0934 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Sat, 4 May 2002 05:28:09 +0000 Subject: [PATCH] Adding the functions JS_LockGCThingRT and JS_UnlockGCThingRT, which are variants that only require a JSRuntime, not a JSContext. Converted some internal callers to use the new interface. Bug 141356, patch from shaver, r=bryner, sr=brendan. --- js/src/jsapi.c | 14 +++++++++++++- js/src/jsapi.h | 6 ++++++ js/src/jsgc.c | 29 +++++++++++++++-------------- js/src/jsgc.h | 5 ++++- js/src/jsnum.c | 6 +++--- js/src/jsstr.c | 2 +- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/js/src/jsapi.c b/js/src/jsapi.c index 8771046c2589..628180c86b88 100644 --- a/js/src/jsapi.c +++ b/js/src/jsapi.c @@ -1608,18 +1608,30 @@ JS_LockGCThing(JSContext *cx, void *thing) return ok; } +JS_PUBLIC_API(JSBool) +JS_LockGCThingRT(JSRuntime *rt, void *thing) +{ + return js_LockGCThingRT(rt, thing); +} + JS_PUBLIC_API(JSBool) JS_UnlockGCThing(JSContext *cx, void *thing) { JSBool ok; CHECK_REQUEST(cx); - ok = js_UnlockGCThing(cx, thing); + ok = js_UnlockGCThingRT(cx->runtime, thing); if (!ok) JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_UNLOCK); return ok; } +JS_PUBLIC_API(JSBool) +JS_UnlockGCThingRT(JSRuntime *rt, void *thing) +{ + return js_UnlockGCThingRT(rt, thing); +} + JS_PUBLIC_API(void) JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 143ec37c156e..01a49e6e8cee 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -592,9 +592,15 @@ JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data); extern JS_PUBLIC_API(JSBool) JS_LockGCThing(JSContext *cx, void *thing); +extern JS_PUBLIC_API(JSBool) +JS_LockGCThingRT(JSRuntime *rt, void *thing); + extern JS_PUBLIC_API(JSBool) JS_UnlockGCThing(JSContext *cx, void *thing); +extern JS_PUBLIC_API(JSBool) +JS_UnlockGCThingRT(JSRuntime *rt, void *thing); + /* * For implementors of JSObjectOps.mark, to mark a GC-thing reachable via a * property or other strong ref identified for debugging purposes by name. diff --git a/js/src/jsgc.c b/js/src/jsgc.c index e29737bcf31c..87cf685cfed6 100644 --- a/js/src/jsgc.c +++ b/js/src/jsgc.c @@ -543,7 +543,15 @@ retry: JSBool js_LockGCThing(JSContext *cx, void *thing) { - JSRuntime *rt; + JSBool ok = js_LockGCThingRT(cx->runtime, thing); + if (!ok) + JS_ReportOutOfMemory(cx); + return ok; +} + +JSBool +js_LockGCThingRT(JSRuntime *rt, void *thing) +{ uint8 *flagp, flags, lockbits; JSBool ok; JSGCLockHashEntry *lhe; @@ -553,8 +561,7 @@ js_LockGCThing(JSContext *cx, void *thing) flagp = js_GetGCThingFlags(thing); flags = *flagp; - ok = JS_TRUE; - rt = cx->runtime; + ok = JS_FALSE; JS_LOCK_GC(rt); lockbits = (flags & GCF_LOCKMASK); @@ -568,7 +575,7 @@ js_LockGCThing(JSContext *cx, void *thing) sizeof(JSGCLockHashEntry), GC_ROOTS_SIZE); if (!rt->gcLocksHash) - goto outofmem; + goto error; } else { #ifdef DEBUG JSDHashEntryHdr *hdr = @@ -580,7 +587,7 @@ js_LockGCThing(JSContext *cx, void *thing) lhe = (JSGCLockHashEntry *) JS_DHashTableOperate(rt->gcLocksHash, thing, JS_DHASH_ADD); if (!lhe) - goto outofmem; + goto error; lhe->thing = thing; lhe->count = 1; *flagp = (uint8)(flags + GCF_LOCK); @@ -603,20 +610,15 @@ js_LockGCThing(JSContext *cx, void *thing) } METER(rt->gcStats.lock++); -out: + ok = JS_TRUE; +error: JS_UNLOCK_GC(rt); return ok; - -outofmem: - JS_ReportOutOfMemory(cx); - ok = JS_FALSE; - goto out; } JSBool -js_UnlockGCThing(JSContext *cx, void *thing) +js_UnlockGCThingRT(JSRuntime *rt, void *thing) { - JSRuntime *rt; uint8 *flagp, flags, lockbits; JSGCLockHashEntry *lhe; @@ -625,7 +627,6 @@ js_UnlockGCThing(JSContext *cx, void *thing) flagp = js_GetGCThingFlags(thing); flags = *flagp; - rt = cx->runtime; JS_LOCK_GC(rt); lockbits = (flags & GCF_LOCKMASK); diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 5d219ba2b622..4aa16c1682a6 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -121,7 +121,10 @@ extern JSBool js_LockGCThing(JSContext *cx, void *thing); extern JSBool -js_UnlockGCThing(JSContext *cx, void *thing); +js_LockGCThingRT(JSRuntime *rt, void *thing); + +extern JSBool +js_UnlockGCThingRT(JSRuntime *rt, void *thing); extern JSBool js_IsAboutToBeFinalized(JSContext *cx, void *thing); diff --git a/js/src/jsnum.c b/js/src/jsnum.c index 9ab81658e5a3..32e359898970 100644 --- a/js/src/jsnum.c +++ b/js/src/jsnum.c @@ -500,9 +500,9 @@ js_FinishRuntimeNumberState(JSContext *cx) { JSRuntime *rt = cx->runtime; - js_UnlockGCThing(cx, rt->jsNaN); - js_UnlockGCThing(cx, rt->jsNegativeInfinity); - js_UnlockGCThing(cx, rt->jsPositiveInfinity); + js_UnlockGCThingRT(rt, rt->jsNaN); + js_UnlockGCThingRT(rt, rt->jsNegativeInfinity); + js_UnlockGCThingRT(rt, rt->jsPositiveInfinity); rt->jsNaN = NULL; rt->jsNegativeInfinity = NULL; diff --git a/js/src/jsstr.c b/js/src/jsstr.c index 58f4e6595343..1c4f9102680b 100644 --- a/js/src/jsstr.c +++ b/js/src/jsstr.c @@ -2316,7 +2316,7 @@ js_FinishRuntimeStringState(JSContext *cx) { JSRuntime *rt = cx->runtime; - js_UnlockGCThing(cx, rt->emptyString); + js_UnlockGCThingRT(rt, rt->emptyString); rt->emptyString = NULL; }