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.

This commit is contained in:
bryner%netscape.com 2002-05-04 05:28:09 +00:00
Родитель b8f54f2222
Коммит 92a1bec8eb
6 изменённых файлов: 42 добавлений и 20 удалений

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -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.

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}