wgl: Move all thread related code together.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 17 Jun 2009 18:24:51 +0000 (19:24 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 18 Jun 2009 13:54:07 +0000 (14:54 +0100)
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).

src/gallium/state_trackers/wgl/shared/stw_device.c
src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
src/gallium/state_trackers/wgl/shared/stw_framebuffer.h
src/gallium/state_trackers/wgl/shared/stw_tls.c
src/gallium/state_trackers/wgl/shared/stw_tls.h

index 1a6b29807d7868995beef6b0fb9f59ba3eb149dc..070ffcb3ca10449e66ee0a0535f5a7100de2dd3c 100644 (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();
 }
 
index 58f18303191f993114006aaee4fc7e721521d8a1..88043859ce4e7d8e7ec31b09a8b60b83fb2fce45 100644 (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;
-   }
-}
index e7fa51c3a81bfe50394584c884a5a4d336bfa2db..d6f5950ac3e948d4661a45984c3070d456dfe68c 100644 (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 */
index 0c18a52352c3037d6a1e87616b0c443dc9e51f51..4bd6a9289c96fa0d9a1a362d4e360dea5bb77acb 100644 (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;
index 6af8be70c9f9daf9e94824d45156a2223ee17eb0..fbf8b1cbee495461cfe4456eaaa11af0985f60bc 100644 (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 */