egl: Remove usage of USE_ELF_TLS macro

After commit c47fd3dc00 ("windows: Use TLS context/dispatch with shared-glapi")
USE_ELF_TLS are always defined by
pre_args += '-DUSE_ELF_TLS'
So we can remove it safety

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17213>
This commit is contained in:
Yonggang Luo 2022-06-21 14:03:41 +08:00 committed by Marge Bot
parent c8d296ae4b
commit bf2cd50019
4 changed files with 35 additions and 180 deletions

View File

@ -267,22 +267,17 @@ static EGLBoolean
_eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object) _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
{ {
_EGLThreadInfo *thr = _eglGetCurrentThread(); _EGLThreadInfo *thr = _eglGetCurrentThread();
if (!_eglIsCurrentThreadDummy()) { thr->CurrentFuncName = funcName;
thr->CurrentFuncName = funcName; thr->CurrentObjectLabel = NULL;
thr->CurrentObjectLabel = NULL;
if (objectType == EGL_OBJECT_THREAD_KHR) if (objectType == EGL_OBJECT_THREAD_KHR)
thr->CurrentObjectLabel = thr->Label; thr->CurrentObjectLabel = thr->Label;
else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp) else if (objectType == EGL_OBJECT_DISPLAY_KHR && disp)
thr->CurrentObjectLabel = disp->Label; thr->CurrentObjectLabel = disp->Label;
else if (object) else if (object)
thr->CurrentObjectLabel = object->Label; thr->CurrentObjectLabel = object->Label;
return EGL_TRUE; return EGL_TRUE;
}
_eglDebugReport(EGL_BAD_ALLOC, funcName, EGL_DEBUG_MSG_CRITICAL_KHR, NULL);
return EGL_FALSE;
} }
#define _EGL_FUNC_START(disp, objectType, object, ret) \ #define _EGL_FUNC_START(disp, objectType, object, ret) \
@ -1645,8 +1640,7 @@ eglGetError(void)
{ {
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLThreadInfo *t = _eglGetCurrentThread();
EGLint e = t->LastError; EGLint e = t->LastError;
if (!_eglIsCurrentThreadDummy()) t->LastError = EGL_SUCCESS;
t->LastError = EGL_SUCCESS;
return e; return e;
} }
@ -1674,8 +1668,6 @@ eglBindAPI(EGLenum api)
_EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
t = _eglGetCurrentThread(); t = _eglGetCurrentThread();
if (_eglIsCurrentThreadDummy())
RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
if (!_eglIsApiValid(api)) if (!_eglIsApiValid(api))
RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE); RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
@ -1723,19 +1715,17 @@ EGLBoolean EGLAPIENTRY
eglReleaseThread(void) eglReleaseThread(void)
{ {
/* unbind current contexts */ /* unbind current contexts */
if (!_eglIsCurrentThreadDummy()) { _EGLThreadInfo *t = _eglGetCurrentThread();
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLContext *ctx = t->CurrentContext;
_EGLContext *ctx = t->CurrentContext;
_EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
if (ctx) { if (ctx) {
_EGLDisplay *disp = ctx->Resource.Display; _EGLDisplay *disp = ctx->Resource.Display;
mtx_lock(&disp->Mutex); mtx_lock(&disp->Mutex);
(void) disp->Driver->MakeCurrent(disp, NULL, NULL, NULL); (void) disp->Driver->MakeCurrent(disp, NULL, NULL, NULL);
mtx_unlock(&disp->Mutex); mtx_unlock(&disp->Mutex);
}
} }
_eglDestroyCurrentThread(); _eglDestroyCurrentThread();
@ -2434,12 +2424,8 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
if (objectType == EGL_OBJECT_THREAD_KHR) { if (objectType == EGL_OBJECT_THREAD_KHR) {
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLThreadInfo *t = _eglGetCurrentThread();
if (!_eglIsCurrentThreadDummy()) { t->Label = label;
t->Label = label; return EGL_SUCCESS;
return EGL_SUCCESS;
}
RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
} }
disp = _eglLockDisplay(dpy); disp = _eglLockDisplay(dpy);

View File

@ -740,9 +740,6 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read)
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLThreadInfo *t = _eglGetCurrentThread();
_EGLDisplay *disp; _EGLDisplay *disp;
if (_eglIsCurrentThreadDummy())
return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent");
/* this is easy */ /* this is easy */
if (!ctx) { if (!ctx) {
if (draw || read) if (draw || read)

View File

@ -38,67 +38,9 @@
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglglobals.h" #include "eglglobals.h"
/* a fallback thread info to guarantee that every thread always has one */ static __THREAD_INITIAL_EXEC _EGLThreadInfo _egl_TLS = {
static _EGLThreadInfo dummy_thread; .inited = false
static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP; };
static EGLBoolean _egl_TSDInitialized;
static tss_t _egl_TSD;
static void _eglDestroyThreadInfo(_EGLThreadInfo *t);
#ifdef USE_ELF_TLS
static __THREAD_INITIAL_EXEC const _EGLThreadInfo *_egl_TLS;
#endif
static inline void _eglSetTSD(const _EGLThreadInfo *t)
{
tss_set(_egl_TSD, (void *) t);
#ifdef USE_ELF_TLS
_egl_TLS = t;
#endif
}
static inline _EGLThreadInfo *_eglGetTSD(void)
{
#ifdef USE_ELF_TLS
return (_EGLThreadInfo *) _egl_TLS;
#else
return (_EGLThreadInfo *) tss_get(_egl_TSD);
#endif
}
static inline void _eglFiniTSD(void)
{
mtx_lock(&_egl_TSDMutex);
if (_egl_TSDInitialized) {
_EGLThreadInfo *t = _eglGetTSD();
_egl_TSDInitialized = EGL_FALSE;
_eglDestroyThreadInfo(t);
tss_delete(_egl_TSD);
}
mtx_unlock(&_egl_TSDMutex);
}
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 *)) _eglDestroyThreadInfo) != thrd_success) {
mtx_unlock(&_egl_TSDMutex);
return EGL_FALSE;
}
_eglAddAtExitCall(_eglFiniTSD);
_egl_TSDInitialized = EGL_TRUE;
}
mtx_unlock(&_egl_TSDMutex);
}
return EGL_TRUE;
}
static void static void
_eglInitThreadInfo(_EGLThreadInfo *t) _eglInitThreadInfo(_EGLThreadInfo *t)
@ -109,70 +51,21 @@ _eglInitThreadInfo(_EGLThreadInfo *t)
} }
/**
* Allocate and init a new _EGLThreadInfo object.
*/
static _EGLThreadInfo *
_eglCreateThreadInfo(void)
{
_EGLThreadInfo *t = calloc(1, sizeof(_EGLThreadInfo));
if (!t)
t = &dummy_thread;
_eglInitThreadInfo(t);
return t;
}
/**
* Delete/free a _EGLThreadInfo object.
*/
static void
_eglDestroyThreadInfo(_EGLThreadInfo *t)
{
if (t != &dummy_thread) {
free(t);
#ifdef USE_ELF_TLS
/* Reset the TLS also here, otherwise
* it will be having a dangling pointer */
_egl_TLS = NULL;
#endif
}
}
/**
* Make sure TSD is initialized and return current value.
*/
static inline _EGLThreadInfo *
_eglCheckedGetTSD(void)
{
if (_eglInitTSD() != EGL_TRUE) {
_eglLog(_EGL_FATAL, "failed to initialize \"current\" system");
return NULL;
}
return _eglGetTSD();
}
/** /**
* Return the calling thread's thread info. * Return the calling thread's thread info.
* If the calling thread nevers calls this function before, or if its thread * If the calling thread nevers calls this function before, or if its thread
* info was destroyed, a new one is created. This function never returns NULL. * info was destroyed, reinitialize it. This function never returns NULL.
* In the case allocation fails, a dummy one is returned. See also
* _eglIsCurrentThreadDummy.
*/ */
_EGLThreadInfo * _EGLThreadInfo *
_eglGetCurrentThread(void) _eglGetCurrentThread(void)
{ {
_EGLThreadInfo *t = _eglCheckedGetTSD(); _EGLThreadInfo *current = &_egl_TLS;
if (!t) { if (unlikely(!current->inited)) {
t = _eglCreateThreadInfo(); memset(current, 0, sizeof(current[0]));
_eglSetTSD(t); _eglInitThreadInfo(current);
current->inited = true;
} }
return current;
return t;
} }
@ -182,25 +75,8 @@ _eglGetCurrentThread(void)
void void
_eglDestroyCurrentThread(void) _eglDestroyCurrentThread(void)
{ {
_EGLThreadInfo *t = _eglCheckedGetTSD(); _EGLThreadInfo *t = _eglGetCurrentThread();
if (t) { t->inited = false;
_eglDestroyThreadInfo(t);
_eglSetTSD(NULL);
}
}
/**
* Return true if the calling thread's thread info is dummy.
* A dummy thread info is shared by all threads and should not be modified.
* Functions like eglBindAPI or eglMakeCurrent should check for dummy-ness
* before updating the thread info.
*/
EGLBoolean
_eglIsCurrentThreadDummy(void)
{
_EGLThreadInfo *t = _eglCheckedGetTSD();
return (!t || t == &dummy_thread);
} }
@ -223,9 +99,6 @@ _eglInternalError(EGLint errCode, const char *msg)
{ {
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLThreadInfo *t = _eglGetCurrentThread();
if (t == &dummy_thread)
return EGL_FALSE;
t->LastError = errCode; t->LastError = errCode;
if (errCode != EGL_SUCCESS) { if (errCode != EGL_SUCCESS) {

View File

@ -29,6 +29,8 @@
#ifndef EGLCURRENT_INCLUDED #ifndef EGLCURRENT_INCLUDED
#define EGLCURRENT_INCLUDED #define EGLCURRENT_INCLUDED
#include <stdbool.h>
#include "egltypedefs.h" #include "egltypedefs.h"
@ -49,6 +51,7 @@ extern "C" {
*/ */
struct _egl_thread_info struct _egl_thread_info
{ {
bool inited;
EGLint LastError; EGLint LastError;
_EGLContext *CurrentContext; _EGLContext *CurrentContext;
EGLenum CurrentAPI; EGLenum CurrentAPI;
@ -86,10 +89,6 @@ extern void
_eglDestroyCurrentThread(void); _eglDestroyCurrentThread(void);
extern EGLBoolean
_eglIsCurrentThreadDummy(void);
extern _EGLContext * extern _EGLContext *
_eglGetCurrentContext(void); _eglGetCurrentContext(void);