wgl: Move all thread related code together.

Not only for cosmetic reasons, but also because we need to set the
SetWindowsHookEx hook for threads created before the DllMain is called
(threads for each we don't get the DLL_THREAD_ATTACH notification).
This commit is contained in:
José Fonseca 2009-06-17 19:24:51 +01:00
parent 1b05b5b4fe
commit 4b4855c717
5 changed files with 33 additions and 58 deletions

View file

@ -133,20 +133,13 @@ error1:
boolean
stw_init_thread(void)
{
if (!stw_tls_init_thread())
return FALSE;
if (!stw_framebuffer_init_thread())
return FALSE;
return TRUE;
return stw_tls_init_thread();
}
void
stw_cleanup_thread(void)
{
stw_framebuffer_cleanup_thread();
stw_tls_cleanup_thread();
}

View file

@ -84,7 +84,7 @@ stw_framebuffer_destroy_locked(
* @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx
* @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx
*/
static LRESULT CALLBACK
LRESULT CALLBACK
stw_call_window_proc(
int nCode,
WPARAM wParam,
@ -423,38 +423,3 @@ stw_swap_layer_buffers(
return FALSE;
}
boolean
stw_framebuffer_init_thread(void)
{
struct stw_tls_data *tls_data;
tls_data = stw_tls_get_data();
if(!tls_data)
return FALSE;
tls_data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC,
stw_call_window_proc,
NULL,
GetCurrentThreadId());
if(tls_data->hCallWndProcHook == NULL)
return FALSE;
return TRUE;
}
void
stw_framebuffer_cleanup_thread(void)
{
struct stw_tls_data *tls_data;
tls_data = stw_tls_get_data();
if(!tls_data)
return;
if(tls_data->hCallWndProcHook) {
UnhookWindowsHookEx(tls_data->hCallWndProcHook);
tls_data->hCallWndProcHook = NULL;
}
}

View file

@ -79,10 +79,4 @@ struct stw_framebuffer *
stw_framebuffer_from_hdc(
HDC hdc );
boolean
stw_framebuffer_init_thread(void);
void
stw_framebuffer_cleanup_thread(void);
#endif /* STW_FRAMEBUFFER_H */

View file

@ -51,9 +51,23 @@ stw_tls_data_create()
data = CALLOC_STRUCT(stw_tls_data);
if (!data)
return NULL;
goto no_data;
data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC,
stw_call_window_proc,
NULL,
GetCurrentThreadId());
if(data->hCallWndProcHook == NULL)
goto no_hook;
TlsSetValue(tlsIndex, data);
return data;
no_hook:
FREE(data);
no_data:
return NULL;
}
boolean
@ -69,8 +83,6 @@ stw_tls_init_thread(void)
if(!data)
return FALSE;
TlsSetValue(tlsIndex, data);
return TRUE;
}
@ -84,8 +96,16 @@ stw_tls_cleanup_thread(void)
}
data = (struct stw_tls_data *) TlsGetValue(tlsIndex);
TlsSetValue(tlsIndex, NULL);
FREE(data);
if(data) {
TlsSetValue(tlsIndex, NULL);
if(data->hCallWndProcHook) {
UnhookWindowsHookEx(data->hCallWndProcHook);
data->hCallWndProcHook = NULL;
}
FREE(data);
}
}
void
@ -110,12 +130,9 @@ stw_tls_get_data(void)
if(!data) {
/* DllMain is called with DLL_THREAD_ATTACH only by threads created after
* the DLL is loaded by the process */
data = stw_tls_data_create();
if(!data)
return NULL;
TlsSetValue(tlsIndex, data);
}
return data;

View file

@ -50,4 +50,10 @@ stw_tls_cleanup(void);
struct stw_tls_data *
stw_tls_get_data(void);
LRESULT CALLBACK
stw_call_window_proc(
int nCode,
WPARAM wParam,
LPARAM lParam );
#endif /* STW_TLS_H */