Revert "egl/main: use c11/threads' mutex directly"

This reverts commit 6cee785c69.

Not meant to go in yet. Lacking review.
This commit is contained in:
Emil Velikov
2015-03-06 17:07:40 +00:00
parent eb14d28e6d
commit 56ede80940
11 changed files with 111 additions and 47 deletions

View File

@@ -26,6 +26,7 @@ LIBEGL_C_FILES := \
eglmisc.h \ eglmisc.h \
eglmode.c \ eglmode.c \
eglmode.h \ eglmode.h \
eglmutex.h \
eglscreen.c \ eglscreen.c \
eglscreen.h \ eglscreen.h \
eglstring.c \ eglstring.c \

View File

@@ -87,8 +87,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "c99_compat.h" #include "c99_compat.h"
#include "c11/threads.h"
#include "eglcompiler.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "eglcontext.h" #include "eglcontext.h"
@@ -277,7 +275,7 @@ _eglLockDisplay(EGLDisplay display)
{ {
_EGLDisplay *dpy = _eglLookupDisplay(display); _EGLDisplay *dpy = _eglLookupDisplay(display);
if (dpy) if (dpy)
mtx_lock(&dpy->Mutex); _eglLockMutex(&dpy->Mutex);
return dpy; return dpy;
} }
@@ -288,7 +286,7 @@ _eglLockDisplay(EGLDisplay display)
static inline void static inline void
_eglUnlockDisplay(_EGLDisplay *dpy) _eglUnlockDisplay(_EGLDisplay *dpy)
{ {
mtx_unlock(&dpy->Mutex); _eglUnlockMutex(&dpy->Mutex);
} }
@@ -898,7 +896,7 @@ eglWaitClient(void)
RETURN_EGL_SUCCESS(NULL, EGL_TRUE); RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display; disp = ctx->Resource.Display;
mtx_lock(&disp->Mutex); _eglLockMutex(&disp->Mutex);
/* let bad current context imply bad current surface */ /* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
@@ -944,7 +942,7 @@ eglWaitNative(EGLint engine)
RETURN_EGL_SUCCESS(NULL, EGL_TRUE); RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display; disp = ctx->Resource.Display;
mtx_lock(&disp->Mutex); _eglLockMutex(&disp->Mutex);
/* let bad current context imply bad current surface */ /* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
@@ -1459,10 +1457,10 @@ eglReleaseThread(void)
t->CurrentAPIIndex = i; t->CurrentAPIIndex = i;
mtx_lock(&disp->Mutex); _eglLockMutex(&disp->Mutex);
drv = disp->Driver; drv = disp->Driver;
(void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL); (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
mtx_unlock(&disp->Mutex); _eglUnlockMutex(&disp->Mutex);
} }
} }

View File

@@ -31,6 +31,7 @@
#include "c99_compat.h" #include "c99_compat.h"
#include "egllog.h" #include "egllog.h"
#include "eglmutex.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglglobals.h" #include "eglglobals.h"
@@ -46,7 +47,7 @@ static _EGLThreadInfo dummy_thread = _EGL_THREAD_INFO_INITIALIZER;
#if HAVE_PTHREAD #if HAVE_PTHREAD
#include <pthread.h> #include <pthread.h>
static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP; static _EGLMutex _egl_TSDMutex = _EGL_MUTEX_INITIALIZER;
static EGLBoolean _egl_TSDInitialized; static EGLBoolean _egl_TSDInitialized;
static pthread_key_t _egl_TSD; static pthread_key_t _egl_TSD;
static void (*_egl_FreeTSD)(_EGLThreadInfo *); static void (*_egl_FreeTSD)(_EGLThreadInfo *);
@@ -75,7 +76,7 @@ static inline _EGLThreadInfo *_eglGetTSD(void)
static inline void _eglFiniTSD(void) static inline void _eglFiniTSD(void)
{ {
mtx_lock(&_egl_TSDMutex); _eglLockMutex(&_egl_TSDMutex);
if (_egl_TSDInitialized) { if (_egl_TSDInitialized) {
_EGLThreadInfo *t = _eglGetTSD(); _EGLThreadInfo *t = _eglGetTSD();
@@ -84,18 +85,18 @@ static inline void _eglFiniTSD(void)
_egl_FreeTSD((void *) t); _egl_FreeTSD((void *) t);
pthread_key_delete(_egl_TSD); pthread_key_delete(_egl_TSD);
} }
mtx_unlock(&_egl_TSDMutex); _eglUnlockMutex(&_egl_TSDMutex);
} }
static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
{ {
if (!_egl_TSDInitialized) { if (!_egl_TSDInitialized) {
mtx_lock(&_egl_TSDMutex); _eglLockMutex(&_egl_TSDMutex);
/* check again after acquiring lock */ /* check again after acquiring lock */
if (!_egl_TSDInitialized) { if (!_egl_TSDInitialized) {
if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) { if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) {
mtx_unlock(&_egl_TSDMutex); _eglUnlockMutex(&_egl_TSDMutex);
return EGL_FALSE; return EGL_FALSE;
} }
_egl_FreeTSD = dtor; _egl_FreeTSD = dtor;
@@ -103,7 +104,7 @@ static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
_egl_TSDInitialized = EGL_TRUE; _egl_TSDInitialized = EGL_TRUE;
} }
mtx_unlock(&_egl_TSDMutex); _eglUnlockMutex(&_egl_TSDMutex);
} }
return EGL_TRUE; return EGL_TRUE;

View File

@@ -35,14 +35,13 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "c11/threads.h"
#include "eglcontext.h" #include "eglcontext.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglsurface.h" #include "eglsurface.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "eglmutex.h"
#include "egllog.h" #include "egllog.h"
/* Includes for _eglNativePlatformDetectNativeDisplay */ /* Includes for _eglNativePlatformDetectNativeDisplay */
@@ -261,7 +260,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
if (plat == _EGL_INVALID_PLATFORM) if (plat == _EGL_INVALID_PLATFORM)
return NULL; return NULL;
mtx_lock(_eglGlobal.Mutex); _eglLockMutex(_eglGlobal.Mutex);
/* search the display list first */ /* search the display list first */
dpy = _eglGlobal.DisplayList; dpy = _eglGlobal.DisplayList;
@@ -275,7 +274,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
if (!dpy) { if (!dpy) {
dpy = calloc(1, sizeof(_EGLDisplay)); dpy = calloc(1, sizeof(_EGLDisplay));
if (dpy) { if (dpy) {
mtx_init(&dpy->Mutex, mtx_plain); _eglInitMutex(&dpy->Mutex);
dpy->Platform = plat; dpy->Platform = plat;
dpy->PlatformDisplay = plat_dpy; dpy->PlatformDisplay = plat_dpy;
@@ -285,7 +284,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
} }
} }
mtx_unlock(_eglGlobal.Mutex); _eglUnlockMutex(_eglGlobal.Mutex);
return dpy; return dpy;
} }
@@ -345,14 +344,14 @@ _eglCheckDisplayHandle(EGLDisplay dpy)
{ {
_EGLDisplay *cur; _EGLDisplay *cur;
mtx_lock(_eglGlobal.Mutex); _eglLockMutex(_eglGlobal.Mutex);
cur = _eglGlobal.DisplayList; cur = _eglGlobal.DisplayList;
while (cur) { while (cur) {
if (cur == (_EGLDisplay *) dpy) if (cur == (_EGLDisplay *) dpy)
break; break;
cur = cur->Next; cur = cur->Next;
} }
mtx_unlock(_eglGlobal.Mutex); _eglUnlockMutex(_eglGlobal.Mutex);
return (cur != NULL); return (cur != NULL);
} }

View File

@@ -32,10 +32,10 @@
#define EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED
#include "c99_compat.h" #include "c99_compat.h"
#include "c11/threads.h"
#include "egltypedefs.h" #include "egltypedefs.h"
#include "egldefines.h" #include "egldefines.h"
#include "eglmutex.h"
#include "eglarray.h" #include "eglarray.h"
@@ -132,7 +132,7 @@ struct _egl_display
/* used to link displays */ /* used to link displays */
_EGLDisplay *Next; _EGLDisplay *Next;
mtx_t Mutex; _EGLMutex Mutex;
_EGLPlatformType Platform; /**< The type of the platform display */ _EGLPlatformType Platform; /**< The type of the platform display */
void *PlatformDisplay; /**< A pointer to the platform display */ void *PlatformDisplay; /**< A pointer to the platform display */

View File

@@ -37,13 +37,13 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "c11/threads.h"
#include "eglstring.h" #include "eglstring.h"
#include "egldefines.h" #include "egldefines.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "egllog.h" #include "egllog.h"
#include "eglmutex.h"
#if defined(_EGL_OS_UNIX) #if defined(_EGL_OS_UNIX)
#include <dlfcn.h> #include <dlfcn.h>
@@ -63,7 +63,7 @@ typedef struct _egl_module {
_EGLDriver *Driver; _EGLDriver *Driver;
} _EGLModule; } _EGLModule;
static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP; static _EGLMutex _eglModuleMutex = _EGL_MUTEX_INITIALIZER;
static _EGLArray *_eglModules; static _EGLArray *_eglModules;
const struct { const struct {
@@ -616,7 +616,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
assert(!dpy->Initialized); assert(!dpy->Initialized);
mtx_lock(&_eglModuleMutex); _eglLockMutex(&_eglModuleMutex);
/* set options */ /* set options */
dpy->Options.TestOnly = test_only; dpy->Options.TestOnly = test_only;
@@ -628,7 +628,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
best_drv = _eglMatchAndInitialize(dpy); best_drv = _eglMatchAndInitialize(dpy);
} }
mtx_unlock(&_eglModuleMutex); _eglUnlockMutex(&_eglModuleMutex);
if (best_drv) { if (best_drv) {
_eglLog(_EGL_DEBUG, "the best driver is %s%s", _eglLog(_EGL_DEBUG, "the best driver is %s%s",

View File

@@ -30,14 +30,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "c11/threads.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglmutex.h"
static mtx_t _eglGlobalMutex = _MTX_INITIALIZER_NP; static _EGLMutex _eglGlobalMutex = _EGL_MUTEX_INITIALIZER;
struct _egl_global _eglGlobal = struct _egl_global _eglGlobal =
{ {
@@ -85,7 +84,7 @@ _eglAddAtExitCall(void (*func)(void))
if (func) { if (func) {
static EGLBoolean registered = EGL_FALSE; static EGLBoolean registered = EGL_FALSE;
mtx_lock(_eglGlobal.Mutex); _eglLockMutex(_eglGlobal.Mutex);
if (!registered) { if (!registered) {
atexit(_eglAtExit); atexit(_eglAtExit);
@@ -95,6 +94,6 @@ _eglAddAtExitCall(void (*func)(void))
assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls)); assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
_eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func; _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
mtx_unlock(_eglGlobal.Mutex); _eglUnlockMutex(_eglGlobal.Mutex);
} }
} }

View File

@@ -32,9 +32,9 @@
#define EGLGLOBALS_INCLUDED #define EGLGLOBALS_INCLUDED
#include <stdbool.h> #include <stdbool.h>
#include "c11/threads.h"
#include "egltypedefs.h" #include "egltypedefs.h"
#include "eglmutex.h"
/** /**
@@ -42,7 +42,7 @@
*/ */
struct _egl_global struct _egl_global
{ {
mtx_t *Mutex; _EGLMutex *Mutex;
/* the list of all displays */ /* the list of all displays */
_EGLDisplay *DisplayList; _EGLDisplay *DisplayList;

View File

@@ -38,24 +38,24 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "c11/threads.h"
#include "egllog.h" #include "egllog.h"
#include "eglstring.h" #include "eglstring.h"
#include "eglmutex.h"
#define MAXSTRING 1000 #define MAXSTRING 1000
#define FALLBACK_LOG_LEVEL _EGL_WARNING #define FALLBACK_LOG_LEVEL _EGL_WARNING
static struct { static struct {
mtx_t mutex; _EGLMutex mutex;
EGLBoolean initialized; EGLBoolean initialized;
EGLint level; EGLint level;
_EGLLogProc logger; _EGLLogProc logger;
EGLint num_messages; EGLint num_messages;
} logging = { } logging = {
_MTX_INITIALIZER_NP, _EGL_MUTEX_INITIALIZER,
EGL_FALSE, EGL_FALSE,
FALLBACK_LOG_LEVEL, FALLBACK_LOG_LEVEL,
NULL, NULL,
@@ -82,7 +82,7 @@ _eglSetLogProc(_EGLLogProc logger)
{ {
EGLint num_messages = 0; EGLint num_messages = 0;
mtx_lock(&logging.mutex); _eglLockMutex(&logging.mutex);
if (logging.logger != logger) { if (logging.logger != logger) {
logging.logger = logger; logging.logger = logger;
@@ -91,7 +91,7 @@ _eglSetLogProc(_EGLLogProc logger)
logging.num_messages = 0; logging.num_messages = 0;
} }
mtx_unlock(&logging.mutex); _eglUnlockMutex(&logging.mutex);
if (num_messages) if (num_messages)
_eglLog(_EGL_DEBUG, _eglLog(_EGL_DEBUG,
@@ -111,9 +111,9 @@ _eglSetLogLevel(EGLint level)
case _EGL_WARNING: case _EGL_WARNING:
case _EGL_INFO: case _EGL_INFO:
case _EGL_DEBUG: case _EGL_DEBUG:
mtx_lock(&logging.mutex); _eglLockMutex(&logging.mutex);
logging.level = level; logging.level = level;
mtx_unlock(&logging.mutex); _eglUnlockMutex(&logging.mutex);
break; break;
default: default:
break; break;
@@ -188,7 +188,7 @@ _eglLog(EGLint level, const char *fmtStr, ...)
if (level > logging.level || level < 0) if (level > logging.level || level < 0)
return; return;
mtx_lock(&logging.mutex); _eglLockMutex(&logging.mutex);
if (logging.logger) { if (logging.logger) {
va_start(args, fmtStr); va_start(args, fmtStr);
@@ -201,7 +201,7 @@ _eglLog(EGLint level, const char *fmtStr, ...)
logging.num_messages++; logging.num_messages++;
} }
mtx_unlock(&logging.mutex); _eglUnlockMutex(&logging.mutex);
if (level == _EGL_FATAL) if (level == _EGL_FATAL)
exit(1); /* or abort()? */ exit(1); /* or abort()? */

66
src/egl/main/eglmutex.h Normal file
View File

@@ -0,0 +1,66 @@
/**************************************************************************
*
* Copyright 2009 Chia-I Wu <olvaffe@gmail.com>
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef EGLMUTEX_INCLUDED
#define EGLMUTEX_INCLUDED
#include "c99_compat.h"
#include "eglcompiler.h"
#include "c11/threads.h"
typedef mtx_t _EGLMutex;
static inline void _eglInitMutex(_EGLMutex *m)
{
mtx_init(m, mtx_plain);
}
static inline void
_eglDestroyMutex(_EGLMutex *m)
{
mtx_destroy(m);
}
static inline void
_eglLockMutex(_EGLMutex *m)
{
mtx_lock(m);
}
static inline void
_eglUnlockMutex(_EGLMutex *m)
{
mtx_unlock(m);
}
#define _EGL_MUTEX_INITIALIZER _MTX_INITIALIZER_NP
#endif /* EGLMUTEX_INCLUDED */

View File

@@ -44,20 +44,20 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "c11/threads.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglmode.h" #include "eglmode.h"
#include "eglsurface.h" #include "eglsurface.h"
#include "eglscreen.h" #include "eglscreen.h"
#include "eglmutex.h"
#ifdef EGL_MESA_screen_surface #ifdef EGL_MESA_screen_surface
/* ugh, no atomic op? */ /* ugh, no atomic op? */
static mtx_t _eglNextScreenHandleMutex = _MTX_INITIALIZER_NP; static _EGLMutex _eglNextScreenHandleMutex = _EGL_MUTEX_INITIALIZER;
static EGLScreenMESA _eglNextScreenHandle = 1; static EGLScreenMESA _eglNextScreenHandle = 1;
@@ -70,10 +70,10 @@ _eglAllocScreenHandle(void)
{ {
EGLScreenMESA s; EGLScreenMESA s;
mtx_lock(&_eglNextScreenHandleMutex); _eglLockMutex(&_eglNextScreenHandleMutex);
s = _eglNextScreenHandle; s = _eglNextScreenHandle;
_eglNextScreenHandle += _EGL_SCREEN_MAX_MODES; _eglNextScreenHandle += _EGL_SCREEN_MAX_MODES;
mtx_unlock(&_eglNextScreenHandleMutex); _eglUnlockMutex(&_eglNextScreenHandleMutex);
return s; return s;
} }