diff options
author | José Fonseca <[email protected]> | 2009-06-17 19:24:51 +0100 |
---|---|---|
committer | José Fonseca <[email protected]> | 2009-06-18 14:54:07 +0100 |
commit | 4b4855c717e839a9ee6353604558543473c020c9 (patch) | |
tree | 29bf8c621b9947e74a7ba9c4e6d07f35f9e531b5 /src/gallium/state_trackers/wgl/shared/stw_tls.c | |
parent | 1b05b5b4fecd9ac8ef34abdda6c085868016ad84 (diff) |
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).
Diffstat (limited to 'src/gallium/state_trackers/wgl/shared/stw_tls.c')
-rw-r--r-- | src/gallium/state_trackers/wgl/shared/stw_tls.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.c b/src/gallium/state_trackers/wgl/shared/stw_tls.c index 0c18a52352c..4bd6a9289c9 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_tls.c +++ b/src/gallium/state_trackers/wgl/shared/stw_tls.c @@ -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; |