/*@{*/
#if defined(GLX_USE_TLS)
-__thread struct _glapi_table *_glapi_tls_Dispatch
+__thread struct mapi_table *u_current_table_tls
__attribute__((tls_model("initial-exec")))
- = (struct _glapi_table *) table_noop_array;
+ = (struct mapi_table *) table_noop_array;
-__thread void * _glapi_tls_Context
+__thread void *u_current_user_tls
__attribute__((tls_model("initial-exec")));
-const struct _glapi_table *_glapi_Dispatch;
-const void *_glapi_Context;
+const struct mapi_table *u_current_table;
+const void *u_current_user;
#else
-struct _glapi_table *_glapi_Dispatch =
- (struct _glapi_table *) table_noop_array;
-void *_glapi_Context;
+struct mapi_table *u_current_table =
+ (struct mapi_table *) table_noop_array;
+void *u_current_user;
#ifdef THREADS
-struct u_tsd _gl_DispatchTSD;
-static struct u_tsd ContextTSD;
+struct u_tsd u_current_table_tsd;
+static struct u_tsd u_current_user_tsd;
static int ThreadSafe;
#endif /* THREADS */
void
-_glapi_destroy_multithread(void)
+u_current_destroy(void)
{
#if defined(THREADS) && defined(WIN32_THREADS)
- u_tsd_destroy(&_gl_DispatchTSD);
- u_tsd_destroy(&ContextTSD);
+ u_tsd_destroy(&u_current_table_tsd);
+ u_tsd_destroy(&u_current_user_tsd);
#endif
}
#if defined(THREADS) && !defined(GLX_USE_TLS)
static void
-_glapi_init_multithread(void)
+u_current_init_tsd(void)
{
- u_tsd_init(&_gl_DispatchTSD);
- u_tsd_init(&ContextTSD);
+ u_tsd_init(&u_current_table_tsd);
+ u_tsd_init(&u_current_user_tsd);
}
/**
* in order to test if multiple threads are being used.
*/
void
-_glapi_check_multithread(void)
+u_current_init(void)
{
static unsigned long knownID;
static int firstCall = 1;
CHECK_MULTITHREAD_LOCK();
if (firstCall) {
- _glapi_init_multithread();
+ u_current_init_tsd();
knownID = u_thread_self();
firstCall = 0;
}
else if (knownID != u_thread_self()) {
ThreadSafe = 1;
- _glapi_set_dispatch(NULL);
- _glapi_set_context(NULL);
+ u_current_set_internal(NULL);
+ u_current_set_user_internal(NULL);
}
CHECK_MULTITHREAD_UNLOCK();
}
#else
void
-_glapi_check_multithread(void)
+u_current_init(void)
{
}
* void from the real context pointer type.
*/
void
-_glapi_set_context(void *context)
+u_current_set_user_internal(void *ptr)
{
+ u_current_init();
+
#if defined(GLX_USE_TLS)
- _glapi_tls_Context = context;
+ u_current_user_tls = ptr;
#elif defined(THREADS)
- u_tsd_set(&ContextTSD, context);
- _glapi_Context = (ThreadSafe) ? NULL : context;
+ u_tsd_set(&u_current_user_tsd, ptr);
+ u_current_user = (ThreadSafe) ? NULL : ptr;
#else
- _glapi_Context = context;
+ u_current_user = ptr;
#endif
}
* void to the real context pointer type.
*/
void *
-_glapi_get_context(void)
+u_current_get_user_internal(void)
{
#if defined(GLX_USE_TLS)
- return _glapi_tls_Context;
+ return u_current_user_tls;
#elif defined(THREADS)
return (ThreadSafe)
- ? u_tsd_get(&ContextTSD)
- : _glapi_Context;
+ ? u_tsd_get(&u_current_user_tsd)
+ : u_current_user;
#else
- return _glapi_Context;
+ return u_current_user;
#endif
}
* table (__glapi_noop_table).
*/
void
-_glapi_set_dispatch(struct _glapi_table *dispatch)
+u_current_set_internal(struct mapi_table *tbl)
{
+ u_current_init();
+
stub_init_once();
- if (!dispatch)
- dispatch = (struct _glapi_table *) table_noop_array;
+ if (!tbl)
+ tbl = (struct mapi_table *) table_noop_array;
#if defined(GLX_USE_TLS)
- _glapi_tls_Dispatch = dispatch;
+ u_current_table_tls = tbl;
#elif defined(THREADS)
- u_tsd_set(&_gl_DispatchTSD, (void *) dispatch);
- _glapi_Dispatch = (ThreadSafe) ? NULL : dispatch;
+ u_tsd_set(&u_current_table_tsd, (void *) tbl);
+ u_current_table = (ThreadSafe) ? NULL : tbl;
#else
- _glapi_Dispatch = dispatch;
+ u_current_table = tbl;
#endif
}
/**
* Return pointer to current dispatch table for calling thread.
*/
-struct _glapi_table *
-_glapi_get_dispatch(void)
+struct mapi_table *
+u_current_get_internal(void)
{
#if defined(GLX_USE_TLS)
- return _glapi_tls_Dispatch;
+ return u_current_table_tls;
#elif defined(THREADS)
- return (ThreadSafe)
- ? (struct _glapi_table *) u_tsd_get(&_gl_DispatchTSD)
- : _glapi_Dispatch;
+ return (struct mapi_table *) ((ThreadSafe) ?
+ u_tsd_get(&u_current_table_tsd) : (void *) u_current_table);
#else
- return _glapi_Dispatch;
+ return u_current_table;
#endif
}
#ifndef _U_CURRENT_H_
#define _U_CURRENT_H_
-#include "u_compiler.h"
-
#ifdef MAPI_GLAPI_CURRENT
#include "glapi/glapi.h"
+/* ugly renames to match glapi.h */
+#define mapi_table _glapi_table
+
+#define u_current_table_tls _glapi_tls_Dispatch
+#define u_current_user_tls _glapi_tls_Context
+#define u_current_table _glapi_Dispatch
+#define u_current_user _glapi_Context
+
+#define u_current_destroy _glapi_destroy_multithread
+#define u_current_init _glapi_check_multithread
+#define u_current_set_internal _glapi_set_dispatch
+#define u_current_get_internal _glapi_get_dispatch
+#define u_current_set_user_internal _glapi_set_context
+#define u_current_get_user_internal _glapi_get_context
+
+#define u_current_table_tsd _gl_DispatchTSD
+
#else /* MAPI_GLAPI_CURRENT */
-struct _glapi_table;
+#include "u_compiler.h"
+
+struct mapi_table;
#ifdef GLX_USE_TLS
-extern __thread struct _glapi_table *_glapi_tls_Dispatch
+extern __thread struct mapi_table *u_current_table_tls
__attribute__((tls_model("initial-exec")));
-extern __thread void *_glapi_tls_Context
+extern __thread void *u_current_user_tls
__attribute__((tls_model("initial-exec")));
-extern const struct _glapi_table *_glapi_Dispatch;
-extern const void *_glapi_Context;
+extern const struct mapi_table *u_current_table;
+extern const void *u_current_user;
#else /* GLX_USE_TLS */
-extern struct _glapi_table *_glapi_Dispatch;
-extern void *_glapi_Context;
+extern struct mapi_table *u_current_table;
+extern void *u_current_user;
#endif /* GLX_USE_TLS */
void
-_glapi_check_multithread(void);
+u_current_init(void);
void
-_glapi_set_context(void *context);
-
-void *
-_glapi_get_context(void);
+u_current_destroy(void);
void
-_glapi_set_dispatch(struct _glapi_table *dispatch);
+u_current_set_internal(struct mapi_table *tbl);
-struct _glapi_table *
-_glapi_get_dispatch(void);
+struct mapi_table *
+u_current_get_internal(void);
void
-_glapi_destroy_multithread(void);
+u_current_set_user_internal(void *ptr);
-
-struct mapi_table;
+void *
+u_current_get_user_internal(void);
static INLINE void
u_current_set(const struct mapi_table *tbl)
{
- _glapi_check_multithread();
- _glapi_set_dispatch((struct _glapi_table *) tbl);
+ u_current_set_internal((struct mapi_table *) tbl);
}
static INLINE const struct mapi_table *
u_current_get(void)
{
#ifdef GLX_USE_TLS
- return (const struct mapi_table *) _glapi_tls_Dispatch;
+ return (const struct mapi_table *) u_current_table_tls;
#else
- return (const struct mapi_table *) (likely(_glapi_Dispatch) ?
- _glapi_Dispatch : _glapi_get_dispatch());
+ return (likely(u_current_table) ?
+ (const struct mapi_table *) u_current_table : u_current_get_internal());
#endif
}
static INLINE void
u_current_set_user(void *ptr)
{
- _glapi_check_multithread();
- _glapi_set_context(ptr);
+ u_current_set_internal(ptr);
}
static INLINE void *
u_current_get_user(void)
{
#ifdef GLX_USE_TLS
- return _glapi_tls_Context;
+ return u_current_user_tls;
#else
- return likely(_glapi_Context) ? _glapi_Context : _glapi_get_context();
+ return likely(u_current_user) ? u_current_user : u_current_get_user_internal();
#endif
}