Ejemplo n.º 1
0
/*
 * Sets current thread as owning thread of a context by assigning the
 * thread-private info to the context. If the current thread doesn't have
 * private JSThread info, create one.
 */
JSBool
js_SetContextThread(JSContext *cx)
{
    JSThread *thread = js_GetCurrentThread(cx->runtime);

    if (!thread) {
        JS_ReportOutOfMemory(cx);
        return JS_FALSE;
    }
    cx->thread = thread;
    JS_REMOVE_LINK(&cx->threadLinks);
    JS_APPEND_LINK(&cx->threadLinks, &thread->contextList);
    return JS_TRUE;
}
Ejemplo n.º 2
0
/* Remove the owning thread info of a context. */
void
js_ClearContextThread(JSContext *cx)
{
    /*
     * If cx is associated with a thread, this must be called only from that
     * thread.  If not, this is a harmless no-op.
     */
    JS_ASSERT(cx->thread == js_GetCurrentThread(cx->runtime) || !cx->thread);
    JS_REMOVE_AND_INIT_LINK(&cx->threadLinks);
#ifdef DEBUG
    if (JS_CLIST_IS_EMPTY(&cx->thread->contextList)) {
        memset(cx->thread->gcFreeLists, JS_FREE_PATTERN,
               sizeof(cx->thread->gcFreeLists));
    }
#endif
    cx->thread = NULL;
}
Ejemplo n.º 3
0
/*
 * Sets current thread as owning thread of a context by assigning the
 * thread-private info to the context. If the current thread doesn't have
 * private JSThread info, create one.
 */
JSBool
js_SetContextThread(JSContext *cx)
{
    JSThread *thread = js_GetCurrentThread(cx->runtime);

    if (!thread) {
        JS_ReportOutOfMemory(cx);
        return JS_FALSE;
    }

    /*
     * Clear gcFreeLists on each transition from 0 to 1 context active on the
     * current thread. See bug 351602.
     */
    if (JS_CLIST_IS_EMPTY(&thread->contextList))
        memset(thread->gcFreeLists, 0, sizeof(thread->gcFreeLists));

    /* Assert that the previous cx->thread called JS_ClearContextThread(). */
    JS_ASSERT(!cx->thread || cx->thread == thread);
    if (!cx->thread)
        JS_APPEND_LINK(&cx->threadLinks, &thread->contextList);
    cx->thread = thread;
    return JS_TRUE;
}