Bug 559442 - 'Fix ctypes closures to work on a non-GC thread'. r=dwitte.

This commit is contained in:
Ben Turner 2010-04-14 17:21:06 -07:00
Родитель 8f42b0dd21
Коммит e56ec35a5b
2 изменённых файлов: 29 добавлений и 4 удалений

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

@ -56,6 +56,19 @@
namespace js {
namespace ctypes {
/*******************************************************************************
** Helper classes
*******************************************************************************/
class ScopedContextThread
{
public:
ScopedContextThread(JSContext* cx) : mCx(cx) { JS_SetContextThread(cx); }
~ScopedContextThread() { JS_ClearContextThread(mCx); }
private:
JSContext* mCx;
};
/*******************************************************************************
** JSAPI function prototypes
*******************************************************************************/
@ -2589,7 +2602,9 @@ CType::FinalizeProtoClass(JSContext* cx, JSObject* obj)
if (!JS_GetReservedSlot(cx, obj, SLOT_CLOSURECX, &slot) || JSVAL_IS_VOID(slot))
return;
JS_DestroyContextNoGC(static_cast<JSContext*>(JSVAL_TO_PRIVATE(slot)));
JSContext* closureCx = static_cast<JSContext*>(JSVAL_TO_PRIVATE(slot));
JS_SetContextThread(closureCx);
JS_DestroyContextNoGC(closureCx);
}
void
@ -4868,8 +4883,15 @@ CClosure::Create(JSContext* cx,
JS_DestroyContextNoGC(cinfo->cx);
return NULL;
}
JS_ClearContextThread(cinfo->cx);
}
#ifdef DEBUG
// We want *this* context's thread here so use cx instead of cinfo->cx.
cinfo->cxThread = JS_GetContextThread(cx);
#endif
cinfo->closureObj = result;
cinfo->typeObj = typeObj;
cinfo->thisObj = thisObj;
@ -4959,10 +4981,10 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData)
JSObject* thisObj = cinfo->thisObj;
JSObject* jsfnObj = cinfo->jsfnObj;
#ifdef JS_THREADSAFE
ScopedContextThread scopedThread(cx);
// Assert that we're on the thread we were created from.
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread));
#endif
JS_ASSERT(cinfo->cxThread == JS_GetContextThread(cx));
JSAutoRequest ar(cx);

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

@ -303,6 +303,9 @@ struct ClosureInfo
JSObject* thisObj; // 'this' object to use for the JS function call
JSObject* jsfnObj; // JS function
ffi_closure* closure; // The C closure itself
#ifdef DEBUG
jsword cxThread; // The thread on which the context may be used
#endif
};
JSBool InitTypeClasses(JSContext* cx, JSObject* parent);