jscript: Move thread_id from JScript struct to TLS data.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
This commit is contained in:
parent
cba29adf06
commit
f55db65292
3 changed files with 59 additions and 12 deletions
|
@ -51,8 +51,8 @@ typedef struct {
|
||||||
LONG ref;
|
LONG ref;
|
||||||
|
|
||||||
DWORD safeopt;
|
DWORD safeopt;
|
||||||
|
struct thread_data *thread_data;
|
||||||
script_ctx_t *ctx;
|
script_ctx_t *ctx;
|
||||||
LONG thread_id;
|
|
||||||
LCID lcid;
|
LCID lcid;
|
||||||
DWORD version;
|
DWORD version;
|
||||||
BOOL html_mode;
|
BOOL html_mode;
|
||||||
|
@ -524,8 +524,10 @@ static void decrease_state(JScript *This, SCRIPTSTATE state)
|
||||||
FIXME("NULL ctx\n");
|
FIXME("NULL ctx\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state == SCRIPTSTATE_UNINITIALIZED || state == SCRIPTSTATE_CLOSED)
|
if((state == SCRIPTSTATE_UNINITIALIZED || state == SCRIPTSTATE_CLOSED) && This->thread_data) {
|
||||||
This->thread_id = 0;
|
release_thread_data(This->thread_data);
|
||||||
|
This->thread_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(This->site) {
|
if(This->site) {
|
||||||
IActiveScriptSite_Release(This->site);
|
IActiveScriptSite_Release(This->site);
|
||||||
|
@ -708,6 +710,8 @@ static ULONG WINAPI JScript_Release(IActiveScript *iface)
|
||||||
This->ctx->active_script = NULL;
|
This->ctx->active_script = NULL;
|
||||||
script_release(This->ctx);
|
script_release(This->ctx);
|
||||||
}
|
}
|
||||||
|
if(This->thread_data)
|
||||||
|
release_thread_data(This->thread_data);
|
||||||
free(This);
|
free(This);
|
||||||
unlock_module();
|
unlock_module();
|
||||||
}
|
}
|
||||||
|
@ -726,6 +730,7 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
|
||||||
IActiveScriptSite *pass)
|
IActiveScriptSite *pass)
|
||||||
{
|
{
|
||||||
JScript *This = impl_from_IActiveScript(iface);
|
JScript *This = impl_from_IActiveScript(iface);
|
||||||
|
struct thread_data *thread_data;
|
||||||
named_item_t *item;
|
named_item_t *item;
|
||||||
LCID lcid;
|
LCID lcid;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
@ -738,8 +743,13 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
|
||||||
if(This->site)
|
if(This->site)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
|
if(!(thread_data = get_thread_data()))
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
if(InterlockedCompareExchangePointer((void**)&This->thread_data, thread_data, NULL)) {
|
||||||
|
release_thread_data(thread_data);
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
if(!This->ctx) {
|
if(!This->ctx) {
|
||||||
script_ctx_t *ctx = calloc(1, sizeof(script_ctx_t));
|
script_ctx_t *ctx = calloc(1, sizeof(script_ctx_t));
|
||||||
|
@ -821,7 +831,7 @@ static HRESULT WINAPI JScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE s
|
||||||
|
|
||||||
TRACE("(%p)->(%d)\n", This, ss);
|
TRACE("(%p)->(%d)\n", This, ss);
|
||||||
|
|
||||||
if(This->thread_id && GetCurrentThreadId() != This->thread_id)
|
if(This->thread_data && This->thread_data->thread_id != GetCurrentThreadId())
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if(ss == SCRIPTSTATE_UNINITIALIZED) {
|
if(ss == SCRIPTSTATE_UNINITIALIZED) {
|
||||||
|
@ -865,7 +875,7 @@ static HRESULT WINAPI JScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *
|
||||||
if(!pssState)
|
if(!pssState)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
if(This->thread_id && This->thread_id != GetCurrentThreadId())
|
if(This->thread_data && This->thread_data->thread_id != GetCurrentThreadId())
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
*pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
|
*pssState = This->ctx ? This->ctx->state : SCRIPTSTATE_UNINITIALIZED;
|
||||||
|
@ -878,7 +888,7 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface)
|
||||||
|
|
||||||
TRACE("(%p)->()\n", This);
|
TRACE("(%p)->()\n", This);
|
||||||
|
|
||||||
if(This->thread_id && This->thread_id != GetCurrentThreadId())
|
if(This->thread_data && This->thread_data->thread_id != GetCurrentThreadId())
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
decrease_state(This, SCRIPTSTATE_CLOSED);
|
decrease_state(This, SCRIPTSTATE_CLOSED);
|
||||||
|
@ -897,7 +907,7 @@ static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
|
||||||
|
|
||||||
TRACE("(%p)->(%s %lx)\n", This, debugstr_w(pstrName), dwFlags);
|
TRACE("(%p)->(%s %lx)\n", This, debugstr_w(pstrName), dwFlags);
|
||||||
|
|
||||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
|
if(!This->thread_data || This->thread_data->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
||||||
|
@ -959,7 +969,7 @@ static HRESULT WINAPI JScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR
|
||||||
if(!ppdisp)
|
if(!ppdisp)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx->global) {
|
if(!This->thread_data || This->thread_data->thread_id != GetCurrentThreadId() || !This->ctx->global) {
|
||||||
*ppdisp = NULL;
|
*ppdisp = NULL;
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1111,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
|
||||||
debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
||||||
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
|
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
|
||||||
|
|
||||||
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
if(!This->thread_data || This->thread_data->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if(pstrItemName) {
|
if(pstrItemName) {
|
||||||
|
@ -1204,7 +1214,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
|
||||||
debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
|
||||||
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
|
wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
|
||||||
|
|
||||||
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
if(!This->thread_data || This->thread_data->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if(pstrItemName) {
|
if(pstrItemName) {
|
||||||
|
|
|
@ -129,6 +129,14 @@ typedef HRESULT (*builtin_setter_t)(script_ctx_t*,jsdisp_t*,jsval_t);
|
||||||
|
|
||||||
HRESULT builtin_set_const(script_ctx_t*,jsdisp_t*,jsval_t);
|
HRESULT builtin_set_const(script_ctx_t*,jsdisp_t*,jsval_t);
|
||||||
|
|
||||||
|
struct thread_data {
|
||||||
|
LONG ref;
|
||||||
|
LONG thread_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct thread_data *get_thread_data(void);
|
||||||
|
void release_thread_data(struct thread_data*);
|
||||||
|
|
||||||
typedef struct named_item_t {
|
typedef struct named_item_t {
|
||||||
jsdisp_t *script_obj;
|
jsdisp_t *script_obj;
|
||||||
IDispatch *disp;
|
IDispatch *disp;
|
||||||
|
|
|
@ -37,8 +37,34 @@ LONG module_ref = 0;
|
||||||
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
||||||
|
|
||||||
HINSTANCE jscript_hinstance;
|
HINSTANCE jscript_hinstance;
|
||||||
|
static DWORD jscript_tls;
|
||||||
static ITypeInfo *dispatch_typeinfo;
|
static ITypeInfo *dispatch_typeinfo;
|
||||||
|
|
||||||
|
struct thread_data *get_thread_data(void)
|
||||||
|
{
|
||||||
|
struct thread_data *thread_data = TlsGetValue(jscript_tls);
|
||||||
|
|
||||||
|
if(!thread_data) {
|
||||||
|
thread_data = calloc(1, sizeof(struct thread_data));
|
||||||
|
if(!thread_data)
|
||||||
|
return NULL;
|
||||||
|
thread_data->thread_id = GetCurrentThreadId();
|
||||||
|
TlsSetValue(jscript_tls, thread_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_data->ref++;
|
||||||
|
return thread_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void release_thread_data(struct thread_data *thread_data)
|
||||||
|
{
|
||||||
|
if(--thread_data->ref)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free(thread_data);
|
||||||
|
TlsSetValue(jscript_tls, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT get_dispatch_typeinfo(ITypeInfo **out)
|
HRESULT get_dispatch_typeinfo(ITypeInfo **out)
|
||||||
{
|
{
|
||||||
ITypeInfo *typeinfo;
|
ITypeInfo *typeinfo;
|
||||||
|
@ -164,13 +190,16 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
DisableThreadLibraryCalls(hInstDLL);
|
DisableThreadLibraryCalls(hInstDLL);
|
||||||
jscript_hinstance = hInstDLL;
|
jscript_hinstance = hInstDLL;
|
||||||
if(!init_strings())
|
jscript_tls = TlsAlloc();
|
||||||
|
if(jscript_tls == TLS_OUT_OF_INDEXES || !init_strings())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
if (lpv) break;
|
if (lpv) break;
|
||||||
if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
|
if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
|
||||||
|
if(jscript_tls != TLS_OUT_OF_INDEXES) TlsFree(jscript_tls);
|
||||||
free_strings();
|
free_strings();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Add table
Reference in a new issue