From 17090cf3efb0db8fa01b502a9c0df27cbd1a67da Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 10 Jul 2009 15:28:55 +0800 Subject: 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 --- src/mesa/glapi/glthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/glapi/glthread.h') diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h index 8ec933a851..a36bea7176 100644 --- a/src/mesa/glapi/glthread.h +++ b/src/mesa/glapi/glthread.h @@ -322,7 +322,7 @@ extern __thread struct _glapi_table * _glapi_tls_Dispatch #elif !defined(GL_CALL) # if defined(THREADS) # define GET_DISPATCH() \ - ((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \ + ((__builtin_expect(_glapi_SingleThreaded, 1)) \ ? _glapi_Dispatch : _glapi_get_dispatch()) # else # define GET_DISPATCH() _glapi_Dispatch -- cgit v1.2.3