summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-06-17 19:24:51 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-06-18 14:54:07 +0100
commit4b4855c717e839a9ee6353604558543473c020c9 (patch)
tree29bf8c621b9947e74a7ba9c4e6d07f35f9e531b5 /src
parent1b05b5b4fecd9ac8ef34abdda6c085868016ad84 (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')
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.c9
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_framebuffer.c37
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_framebuffer.h6
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_tls.c33
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_tls.h6
5 files changed, 33 insertions, 58 deletions
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c
index 1a6b29807d..070ffcb3ca 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_device.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_device.c
@@ -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();
}
diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
index 58f1830319..88043859ce 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
@@ -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;
- }
-}
diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h
index e7fa51c3a8..d6f5950ac3 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h
@@ -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 */
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.c b/src/gallium/state_trackers/wgl/shared/stw_tls.c
index 0c18a52352..4bd6a9289c 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;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h
index 6af8be70c9..fbf8b1cbee 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_tls.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h
@@ -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 */