summaryrefslogtreecommitdiff
path: root/src/mapi/mapi/u_current.h
diff options
context:
space:
mode:
authorChia-I Wu <olv@lunarg.com>2010-04-23 16:06:26 +0800
committerChia-I Wu <olv@lunarg.com>2010-05-07 10:41:11 +0800
commita73c6540d9a7f6e26d8568ba2fc522cb865f0a6c (patch)
treeedeb695b6ed24d3cb0016fbabadea48931de779f /src/mapi/mapi/u_current.h
parent296adbd545b8efd38c9ed508166b2de2764a444b (diff)
mapi: Add mapi and share the code with glapi.
Specifically, move all or most of glapi/glapi.c to mapi/u_current.c, glapi/glapi_execmem.c to mapi/u_execmem.c, glapi/glthread.[ch] to mapi/u_thread.[ch] and remove their dependencies on core Mesa headers.
Diffstat (limited to 'src/mapi/mapi/u_current.h')
-rw-r--r--src/mapi/mapi/u_current.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h
new file mode 100644
index 0000000000..a6256f5b51
--- /dev/null
+++ b/src/mapi/mapi/u_current.h
@@ -0,0 +1,93 @@
+#ifndef _U_CURRENT_H_
+#define _U_CURRENT_H_
+
+#include "u_compiler.h"
+
+#ifdef MAPI_GLAPI_CURRENT
+#define GLAPI_EXPORT PUBLIC
+#else
+#define GLAPI_EXPORT
+#endif
+
+/*
+ * Unlike other utility functions, we need to keep the old names (_glapi_*) for
+ * ABI compatibility. The desired functions are wrappers to the old ones.
+ */
+
+struct _glapi_table;
+
+#ifdef GLX_USE_TLS
+
+GLAPI_EXPORT extern __thread struct _glapi_table *_glapi_tls_Dispatch
+ __attribute__((tls_model("initial-exec")));
+
+GLAPI_EXPORT extern __thread void *_glapi_tls_Context
+ __attribute__((tls_model("initial-exec")));
+
+GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
+GLAPI_EXPORT extern const void *_glapi_Context;
+
+#else /* GLX_USE_TLS */
+
+GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch;
+GLAPI_EXPORT extern void *_glapi_Context;
+
+#endif /* GLX_USE_TLS */
+
+GLAPI_EXPORT void
+_glapi_check_multithread(void);
+
+GLAPI_EXPORT void
+_glapi_set_context(void *context);
+
+GLAPI_EXPORT void *
+_glapi_get_context(void);
+
+GLAPI_EXPORT void
+_glapi_set_dispatch(struct _glapi_table *dispatch);
+
+GLAPI_EXPORT struct _glapi_table *
+_glapi_get_dispatch(void);
+
+void
+_glapi_destroy_multithread(void);
+
+
+struct mapi_table;
+
+static INLINE void
+u_current_set(const struct mapi_table *tbl)
+{
+ _glapi_check_multithread();
+ _glapi_set_dispatch((struct _glapi_table *) tbl);
+}
+
+static INLINE const struct mapi_table *
+u_current_get(void)
+{
+#ifdef GLX_USE_TLS
+ return (const struct mapi_table *) _glapi_tls_Dispatch;
+#else
+ return (const struct mapi_table *) (likely(_glapi_Dispatch) ?
+ _glapi_Dispatch : _glapi_get_dispatch());
+#endif
+}
+
+static INLINE void
+u_current_set_user(void *ptr)
+{
+ _glapi_check_multithread();
+ _glapi_set_context(ptr);
+}
+
+static INLINE void *
+u_current_get_user(void)
+{
+#ifdef GLX_USE_TLS
+ return _glapi_tls_Context;
+#else
+ return likely(_glapi_Context) ? _glapi_Context : _glapi_get_context();
+#endif
+}
+
+#endif /* GLX_USE_TLS */