glapi: minor ugliness to be able to copy to xorg
[mesa.git] / src / mesa / glapi / glapi.c
index 30aec209e7dc7301394c2b72a72a581714d95a0f..631ffba3c7fdb399cb3d084b68ef5f0827af7069 100644 (file)
 
 
 #ifdef HAVE_DIX_CONFIG_H
-
 #include <dix-config.h>
-#define PUBLIC
-
+#include "glapi/mesa.h"
 #else
-
 #include "main/glheader.h"
-
-#endif
-
 #include "main/compiler.h"
-
-#include <stdlib.h>
-#include <string.h>
-#ifdef DEBUG
-#include <assert.h>
 #endif
 
-#include "glapi.h"
-#include "glapioffsets.h"
-#include "glapitable.h"
-
-
-/***** BEGIN NO-OP DISPATCH *****/
-
-static GLboolean WarnFlag = GL_FALSE;
-static _glapi_warning_func warning_func;
-
-/*
- * Enable/disable printing of warning messages.
- */
-PUBLIC void
-_glapi_noop_enable_warnings(GLboolean enable)
-{
-   WarnFlag = enable;
-}
-
-/*
- * Register a callback function for reporting errors.
- */
-PUBLIC void
-_glapi_set_warning_func( _glapi_warning_func func )
-{
-   warning_func = func;
-}
-
-static GLboolean
-warn(void)
-{
-#if !defined(_WIN32_WCE)
-   if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
-       && warning_func) {
-      return GL_TRUE;
-   }
-   else {
-      return GL_FALSE;
-   }
-#else
-   return GL_FALSE;
-#endif
-}
-
-
-#define KEYWORD1 static
-#define KEYWORD1_ALT static
-#define KEYWORD2 GLAPIENTRY
-#define NAME(func)  NoOp##func
-
-#define F NULL
-
-#define DISPATCH(func, args, msg)                                            \
-   if (warn()) {                                                             \
-      warning_func(NULL, "GL User Error: called without context: %s", #func); \
-   }
-
-#define RETURN_DISPATCH(func, args, msg)                                     \
-   if (warn()) {                                                             \
-      warning_func(NULL, "GL User Error: called without context: %s", #func); \
-   }                                                                         \
-   return 0
-
-#define DISPATCH_TABLE_NAME __glapi_noop_table
-#define UNUSED_TABLE_NAME __unused_noop_functions
-
-#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
-
-static GLint NoOpUnused(void)
-{
-   if (warn()) {
-      warning_func(NULL, "GL User Error: calling extension function without a current context\n");
-   }
-   return 0;
-}
-
-#include "glapitemp.h"
-
-/***** END NO-OP DISPATCH *****/
+#include "glapi/glapi.h"
+#include "glapi/glapioffsets.h"
+#include "glapi/glapitable.h"
 
+extern _glapi_proc __glapi_noop_table[];
 
 
 /**
@@ -198,7 +112,16 @@ PUBLIC const void *_glapi_Context = NULL;
 
 #if defined(THREADS)
 
+#ifdef WIN32_THREADS
+/* _glthread_DECLARE_STATIC_MUTEX is broken on windows.  There will be race! */
+#define CHECK_MULTITHREAD_LOCK()
+#define CHECK_MULTITHREAD_UNLOCK()
+#else
 _glthread_DECLARE_STATIC_MUTEX(ThreadCheckMutex);
+#define CHECK_MULTITHREAD_LOCK() _glthread_LOCK_MUTEX(ThreadCheckMutex)
+#define CHECK_MULTITHREAD_UNLOCK() _glthread_UNLOCK_MUTEX(ThreadCheckMutex)
+#endif
+
 static GLboolean ThreadSafe = GL_FALSE;  /**< In thread-safe mode? */
 _glthread_TSD _gl_DispatchTSD;           /**< Per-thread dispatch pointer */
 static _glthread_TSD ContextTSD;         /**< Per-thread context pointer */
@@ -228,7 +151,7 @@ PUBLIC void *_glapi_Context = NULL;
  * We should call this periodically from a function such as glXMakeCurrent
  * in order to test if multiple threads are being used.
  */
-void
+PUBLIC void
 _glapi_check_multithread(void)
 {
 #if defined(THREADS) && !defined(GLX_USE_TLS)
@@ -238,8 +161,12 @@ _glapi_check_multithread(void)
    if (ThreadSafe)
       return;
 
-   _glthread_LOCK_MUTEX(ThreadCheckMutex);
+   CHECK_MULTITHREAD_LOCK();
    if (firstCall) {
+      /* initialize TSDs */
+      (void) _glthread_GetTSD(&ContextTSD);
+      (void) _glthread_GetTSD(&_gl_DispatchTSD);
+
       knownID = _glthread_GetID();
       firstCall = GL_FALSE;
    }
@@ -248,7 +175,7 @@ _glapi_check_multithread(void)
       _glapi_set_dispatch(NULL);
       _glapi_set_context(NULL);
    }
-   _glthread_UNLOCK_MUTEX(ThreadCheckMutex);
+   CHECK_MULTITHREAD_UNLOCK();
 #endif
 }
 
@@ -262,7 +189,6 @@ _glapi_check_multithread(void)
 PUBLIC void
 _glapi_set_context(void *context)
 {
-   (void) __unused_noop_functions; /* silence a warning */
 #if defined(GLX_USE_TLS)
    _glapi_tls_Context = context;
 #elif defined(THREADS)