summaryrefslogtreecommitdiffstats
path: root/src/mesa/glapi/glapi.h
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2009-07-10 15:28:55 +0800
committerBrian Paul <[email protected]>2009-08-24 11:46:15 -0600
commit17090cf3efb0db8fa01b502a9c0df27cbd1a67da (patch)
tree60b29d7e22a9326b8747dbb4a3d5fa495b9b758c /src/mesa/glapi/glapi.h
parent3076d1617db67d49ff773096123c1fa47af58272 (diff)
glapi: Fix a possible race in getting current context/dispatch.
There is a possbile race that _glapi_Context is reset by another thread after it is tested in GET_CURRENT_CONTEXT but before it is returned. We definitely do not want a lock here to solve the race. To have correct results even under a race, no other threads should reset _glapi_Context (or _glapi_Dispatch). This patch adds a new global variable _glapi_SingleThreaded. Since _glapi_Context or _glapi_Dispatch are no longer reset, _glapi_SingleThreaded is tested instead, before accessing them. DRI drivers compiled with this patch applied will not work with existing libGL.so because of the missing new symbol. If this turns out to be a real problem, this patch should be reverted. Signed-off-by: Chia-I Wu <[email protected]>
Diffstat (limited to 'src/mesa/glapi/glapi.h')
-rw-r--r--src/mesa/glapi/glapi.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mesa/glapi/glapi.h b/src/mesa/glapi/glapi.h
index 8f2cf662183..b2a1fe6ee93 100644
--- a/src/mesa/glapi/glapi.h
+++ b/src/mesa/glapi/glapi.h
@@ -94,7 +94,10 @@ extern void *_glapi_Context;
extern struct _glapi_table *_glapi_Dispatch;
# ifdef THREADS
-# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
+/* this variable is here only for quick access to current context/dispatch */
+extern GLboolean _glapi_SingleThreaded;
+# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) \
+ ((_glapi_SingleThreaded) ? _glapi_Context : _glapi_get_context())
# else
# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
# endif