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:
parent
c8d296ae4b
commit
bf2cd50019
|
@ -267,7 +267,6 @@ static EGLBoolean
|
|||
_eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object)
|
||||
{
|
||||
_EGLThreadInfo *thr = _eglGetCurrentThread();
|
||||
if (!_eglIsCurrentThreadDummy()) {
|
||||
thr->CurrentFuncName = funcName;
|
||||
thr->CurrentObjectLabel = NULL;
|
||||
|
||||
|
@ -281,10 +280,6 @@ _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EG
|
|||
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) \
|
||||
do { \
|
||||
if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \
|
||||
|
@ -1645,7 +1640,6 @@ eglGetError(void)
|
|||
{
|
||||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
EGLint e = t->LastError;
|
||||
if (!_eglIsCurrentThreadDummy())
|
||||
t->LastError = EGL_SUCCESS;
|
||||
return e;
|
||||
}
|
||||
|
@ -1674,8 +1668,6 @@ eglBindAPI(EGLenum api)
|
|||
_EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL, EGL_FALSE);
|
||||
|
||||
t = _eglGetCurrentThread();
|
||||
if (_eglIsCurrentThreadDummy())
|
||||
RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE);
|
||||
|
||||
if (!_eglIsApiValid(api))
|
||||
RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
|
||||
|
@ -1723,7 +1715,6 @@ EGLBoolean EGLAPIENTRY
|
|||
eglReleaseThread(void)
|
||||
{
|
||||
/* unbind current contexts */
|
||||
if (!_eglIsCurrentThreadDummy()) {
|
||||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
_EGLContext *ctx = t->CurrentContext;
|
||||
|
||||
|
@ -1736,7 +1727,6 @@ eglReleaseThread(void)
|
|||
(void) disp->Driver->MakeCurrent(disp, NULL, NULL, NULL);
|
||||
mtx_unlock(&disp->Mutex);
|
||||
}
|
||||
}
|
||||
|
||||
_eglDestroyCurrentThread();
|
||||
|
||||
|
@ -2434,14 +2424,10 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
|
|||
if (objectType == EGL_OBJECT_THREAD_KHR) {
|
||||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
|
||||
if (!_eglIsCurrentThreadDummy()) {
|
||||
t->Label = label;
|
||||
return EGL_SUCCESS;
|
||||
}
|
||||
|
||||
RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_BAD_ALLOC);
|
||||
}
|
||||
|
||||
disp = _eglLockDisplay(dpy);
|
||||
if (disp == NULL)
|
||||
RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY);
|
||||
|
|
|
@ -740,9 +740,6 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read)
|
|||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
_EGLDisplay *disp;
|
||||
|
||||
if (_eglIsCurrentThreadDummy())
|
||||
return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent");
|
||||
|
||||
/* this is easy */
|
||||
if (!ctx) {
|
||||
if (draw || read)
|
||||
|
|
|
@ -38,67 +38,9 @@
|
|||
#include "eglcurrent.h"
|
||||
#include "eglglobals.h"
|
||||
|
||||
/* a fallback thread info to guarantee that every thread always has one */
|
||||
static _EGLThreadInfo dummy_thread;
|
||||
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 __THREAD_INITIAL_EXEC _EGLThreadInfo _egl_TLS = {
|
||||
.inited = false
|
||||
};
|
||||
|
||||
static void
|
||||
_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.
|
||||
* 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.
|
||||
* In the case allocation fails, a dummy one is returned. See also
|
||||
* _eglIsCurrentThreadDummy.
|
||||
* info was destroyed, reinitialize it. This function never returns NULL.
|
||||
*/
|
||||
_EGLThreadInfo *
|
||||
_eglGetCurrentThread(void)
|
||||
{
|
||||
_EGLThreadInfo *t = _eglCheckedGetTSD();
|
||||
if (!t) {
|
||||
t = _eglCreateThreadInfo();
|
||||
_eglSetTSD(t);
|
||||
_EGLThreadInfo *current = &_egl_TLS;
|
||||
if (unlikely(!current->inited)) {
|
||||
memset(current, 0, sizeof(current[0]));
|
||||
_eglInitThreadInfo(current);
|
||||
current->inited = true;
|
||||
}
|
||||
|
||||
return t;
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,25 +75,8 @@ _eglGetCurrentThread(void)
|
|||
void
|
||||
_eglDestroyCurrentThread(void)
|
||||
{
|
||||
_EGLThreadInfo *t = _eglCheckedGetTSD();
|
||||
if (t) {
|
||||
_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);
|
||||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
t->inited = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,9 +99,6 @@ _eglInternalError(EGLint errCode, const char *msg)
|
|||
{
|
||||
_EGLThreadInfo *t = _eglGetCurrentThread();
|
||||
|
||||
if (t == &dummy_thread)
|
||||
return EGL_FALSE;
|
||||
|
||||
t->LastError = errCode;
|
||||
|
||||
if (errCode != EGL_SUCCESS) {
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#ifndef EGLCURRENT_INCLUDED
|
||||
#define EGLCURRENT_INCLUDED
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "egltypedefs.h"
|
||||
|
||||
|
||||
|
@ -49,6 +51,7 @@ extern "C" {
|
|||
*/
|
||||
struct _egl_thread_info
|
||||
{
|
||||
bool inited;
|
||||
EGLint LastError;
|
||||
_EGLContext *CurrentContext;
|
||||
EGLenum CurrentAPI;
|
||||
|
@ -86,10 +89,6 @@ extern void
|
|||
_eglDestroyCurrentThread(void);
|
||||
|
||||
|
||||
extern EGLBoolean
|
||||
_eglIsCurrentThreadDummy(void);
|
||||
|
||||
|
||||
extern _EGLContext *
|
||||
_eglGetCurrentContext(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue