summaryrefslogtreecommitdiffstats
path: root/src/mesa/glapi/glapi.h
diff options
context:
space:
mode:
authorGeorge Sapountzis <[email protected]>2010-02-26 20:58:24 +0200
committerGeorge Sapountzis <[email protected]>2010-03-01 20:54:17 +0200
commita4ec52f245746b477b673e7cfb9b73d711bfa0d6 (patch)
treeb4efcaa568e291a8fcaab452a5c10bdeab068eab /src/mesa/glapi/glapi.h
parent9a2c4f907b87e81173f50222c4bc325064609392 (diff)
glapi.h: consolidate GET_DISPATCH() and GET_CURRENT_CONTEXT() macros
Use likely() macro, as this is what most projects use. Drops GL_CALL define, cannot find it in mesa tree. Also, whitespace cleaunps in glthread.h
Diffstat (limited to 'src/mesa/glapi/glapi.h')
-rw-r--r--src/mesa/glapi/glapi.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/mesa/glapi/glapi.h b/src/mesa/glapi/glapi.h
index f802a61d3bd..6bfe741b7ef 100644
--- a/src/mesa/glapi/glapi.h
+++ b/src/mesa/glapi/glapi.h
@@ -64,6 +64,15 @@ typedef void (*_glapi_proc)(void); /* generic function pointer */
#endif
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+# define likely(x) __builtin_expect(!!(x), 1)
+# define unlikely(x) __builtin_expect(!!(x), 0)
+#else
+# define likely(x) (x)
+# define unlikely(x) (x)
+#endif
+
+
/*
* Number of extension functions which we can dynamically add at runtime.
*/
@@ -71,7 +80,8 @@ typedef void (*_glapi_proc)(void); /* generic function pointer */
/**
- ** Define the GET_CURRENT_CONTEXT() macro.
+ ** Define the GET_DISPATCH() and GET_CURRENT_CONTEXT() macros.
+ **
** \param C local variable which will hold the current context.
**/
#if defined (GLX_USE_TLS)
@@ -79,9 +89,14 @@ typedef void (*_glapi_proc)(void); /* generic function pointer */
extern const void *_glapi_Context;
extern const struct _glapi_table *_glapi_Dispatch;
+extern __thread struct _glapi_table * _glapi_tls_Dispatch
+ __attribute__((tls_model("initial-exec")));
+
extern __thread void * _glapi_tls_Context
__attribute__((tls_model("initial-exec")));
+# define GET_DISPATCH() _glapi_tls_Dispatch
+
# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_tls_Context
#else
@@ -90,9 +105,19 @@ 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())
+
+# define GET_DISPATCH() \
+ (likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch())
+
+# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) \
+ (likely(_glapi_Context) ? _glapi_Context : _glapi_get_context())
+
# else
+
+# define GET_DISPATCH() _glapi_Dispatch
+
# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
+
# endif
#endif /* defined (GLX_USE_TLS) */