Mesa (master): wgl: Cope with pre-existing threads.
Jose Fonseca
jrfonseca at kemper.freedesktop.org
Mon Apr 27 17:54:41 UTC 2009
Module: Mesa
Branch: master
Commit: 76b9da9e98bad4bf22fe6610394236203b620bd9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=76b9da9e98bad4bf22fe6610394236203b620bd9
Author: José Fonseca <jfonseca at vmware.com>
Date: Mon Apr 27 18:48:11 2009 +0100
wgl: Cope with pre-existing threads.
DllMain is called with DLL_THREAD_ATTACH only by threads created after
the DLL is loaded by the process.
---
src/gallium/state_trackers/wgl/shared/stw_tls.c | 39 ++++++++++++++++++-----
1 files changed, 31 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 e72bafb..95863ca 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_tls.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_tls.c
@@ -44,6 +44,20 @@ stw_tls_init(void)
return TRUE;
}
+static INLINE struct stw_tls_data *
+stw_tls_data_create()
+{
+ struct stw_tls_data *data;
+
+ data = CALLOC_STRUCT(stw_tls_data);
+ if (!data)
+ return NULL;
+
+ data->currentPixelFormat = 0;
+
+ return data;
+}
+
boolean
stw_tls_init_thread(void)
{
@@ -53,14 +67,9 @@ stw_tls_init_thread(void)
return FALSE;
}
- data = MALLOC(sizeof(*data));
- if (!data) {
+ data = stw_tls_data_create();
+ if(!data)
return FALSE;
- }
-
- data->currentPixelFormat = 0;
- data->currentDC = NULL;
- data->currentGLRC = 0;
TlsSetValue(tlsIndex, data);
@@ -93,9 +102,23 @@ stw_tls_cleanup(void)
struct stw_tls_data *
stw_tls_get_data(void)
{
+ struct stw_tls_data *data;
+
if (tlsIndex == TLS_OUT_OF_INDEXES) {
return NULL;
}
+
+ data = (struct stw_tls_data *) TlsGetValue(tlsIndex);
+ 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 (struct stw_tls_data *) TlsGetValue(tlsIndex);
+ return data;
}
More information about the mesa-commit
mailing list