egl: drop unused _EGLDriver from Terminate()
[mesa.git] / src / egl / main / eglcurrent.c
index 7af3011b75764deeebc65abe1a7136f794291c59..29be426802562e15efe3dafdebfc3582577da49f 100644 (file)
@@ -42,9 +42,9 @@ static _EGLThreadInfo dummy_thread;
 static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP;
 static EGLBoolean _egl_TSDInitialized;
 static tss_t _egl_TSD;
-static void (*_egl_FreeTSD)(_EGLThreadInfo *);
+static void _eglDestroyThreadInfo(_EGLThreadInfo *t);
 
-#ifdef GLX_USE_TLS
+#ifdef USE_ELF_TLS
 static __thread const _EGLThreadInfo *_egl_TLS
    __attribute__ ((tls_model("initial-exec")));
 #endif
@@ -52,14 +52,14 @@ static __thread const _EGLThreadInfo *_egl_TLS
 static inline void _eglSetTSD(const _EGLThreadInfo *t)
 {
    tss_set(_egl_TSD, (void *) t);
-#ifdef GLX_USE_TLS
+#ifdef USE_ELF_TLS
    _egl_TLS = t;
 #endif
 }
 
 static inline _EGLThreadInfo *_eglGetTSD(void)
 {
-#ifdef GLX_USE_TLS
+#ifdef USE_ELF_TLS
    return (_EGLThreadInfo *) _egl_TLS;
 #else
    return (_EGLThreadInfo *) tss_get(_egl_TSD);
@@ -73,25 +73,23 @@ static inline void _eglFiniTSD(void)
       _EGLThreadInfo *t = _eglGetTSD();
 
       _egl_TSDInitialized = EGL_FALSE;
-      if (t && _egl_FreeTSD)
-         _egl_FreeTSD((void *) t);
+      _eglDestroyThreadInfo(t);
       tss_delete(_egl_TSD);
    }
    mtx_unlock(&_egl_TSDMutex);
 }
 
-static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
+static inline EGLBoolean _eglInitTSD()
 {
    if (!_egl_TSDInitialized) {
       mtx_lock(&_egl_TSDMutex);
 
       /* check again after acquiring lock */
       if (!_egl_TSDInitialized) {
-         if (tss_create(&_egl_TSD, (void (*)(void *)) dtor) != thrd_success) {
+         if (tss_create(&_egl_TSD, (void (*)(void *)) _eglDestroyThreadInfo) != thrd_success) {
             mtx_unlock(&_egl_TSDMutex);
             return EGL_FALSE;
          }
-         _egl_FreeTSD = dtor;
          _eglAddAtExitCall(_eglFiniTSD);
          _egl_TSDInitialized = EGL_TRUE;
       }
@@ -143,7 +141,7 @@ _eglDestroyThreadInfo(_EGLThreadInfo *t)
 static inline _EGLThreadInfo *
 _eglCheckedGetTSD(void)
 {
-   if (_eglInitTSD(&_eglDestroyThreadInfo) != EGL_TRUE) {
+   if (_eglInitTSD() != EGL_TRUE) {
       _eglLog(_EGL_FATAL, "failed to initialize \"current\" system");
       return NULL;
    }
@@ -310,20 +308,28 @@ _eglDebugReport(EGLenum error, const char *funcName,
 
    mtx_unlock(_eglGlobal.Mutex);
 
-   if (callback != NULL) {
-      char *buf = NULL;
+   char *message_buf = NULL;
+   if (message != NULL) {
+      va_start(args, message);
+      if (vasprintf(&message_buf, message, args) < 0)
+         message_buf = NULL;
+      va_end(args);
+   }
 
-      if (message != NULL) {
-         va_start(args, message);
-         if (vasprintf(&buf, message, args) < 0)
-            buf = NULL;
+   if (callback != NULL) {
+      callback(error, funcName, type, thr->Label, thr->CurrentObjectLabel,
+               message_buf);
+   }
 
-         va_end(args);
+   if (type == EGL_DEBUG_MSG_CRITICAL_KHR || type == EGL_DEBUG_MSG_ERROR_KHR) {
+      char *func_message_buf = NULL;
+      /* Note: _eglError() is often called with msg == thr->currentFuncName */
+      if (message_buf && funcName && strcmp(message_buf, funcName) != 0) {
+         if (asprintf(&func_message_buf, "%s: %s", funcName, message_buf) < 0)
+            func_message_buf = NULL;
       }
-      callback(error, funcName, type, thr->Label, thr->CurrentObjectLabel, buf);
-      free(buf);
+      _eglInternalError(error, func_message_buf ? func_message_buf : funcName);
+      free(func_message_buf);
    }
-
-   if (type == EGL_DEBUG_MSG_CRITICAL_KHR || type == EGL_DEBUG_MSG_ERROR_KHR)
-      _eglInternalError(error, funcName);
+   free(message_buf);
 }