summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-03-06 16:54:55 +0000
committerEmil Velikov <emil.l.velikov@gmail.com>2015-03-11 23:28:25 +0000
commitefe87f1a801c61d087cd2b29a2c150453241c3d4 (patch)
treed7decbfd791f6ee4ab728d10f8573984a4bad4ee
parent90e50908d7f080d91f41d889cfe0dc67134971eb (diff)
egl/main: use c11/threads' mutex directly
Remove the inline wrappers/abstraction layer. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r--src/egl/main/Makefile.sources1
-rw-r--r--src/egl/main/eglapi.c14
-rw-r--r--src/egl/main/eglcurrent.c13
-rw-r--r--src/egl/main/egldisplay.c13
-rw-r--r--src/egl/main/egldisplay.h4
-rw-r--r--src/egl/main/egldriver.c8
-rw-r--r--src/egl/main/eglglobals.c9
-rw-r--r--src/egl/main/eglglobals.h4
-rw-r--r--src/egl/main/egllog.c18
-rw-r--r--src/egl/main/eglmutex.h66
-rw-r--r--src/egl/main/eglscreen.c8
11 files changed, 47 insertions, 111 deletions
diff --git a/src/egl/main/Makefile.sources b/src/egl/main/Makefile.sources
index 6a917e22022..75f060a456a 100644
--- a/src/egl/main/Makefile.sources
+++ b/src/egl/main/Makefile.sources
@@ -26,7 +26,6 @@ LIBEGL_C_FILES := \
eglmisc.h \
eglmode.c \
eglmode.h \
- eglmutex.h \
eglscreen.c \
eglscreen.h \
eglstring.c \
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 22588300644..a74efcd8f99 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -87,6 +87,8 @@
#include <stdlib.h>
#include <string.h>
#include "c99_compat.h"
+#include "c11/threads.h"
+#include "eglcompiler.h"
#include "eglglobals.h"
#include "eglcontext.h"
@@ -275,7 +277,7 @@ _eglLockDisplay(EGLDisplay display)
{
_EGLDisplay *dpy = _eglLookupDisplay(display);
if (dpy)
- _eglLockMutex(&dpy->Mutex);
+ mtx_lock(&dpy->Mutex);
return dpy;
}
@@ -286,7 +288,7 @@ _eglLockDisplay(EGLDisplay display)
static inline void
_eglUnlockDisplay(_EGLDisplay *dpy)
{
- _eglUnlockMutex(&dpy->Mutex);
+ mtx_unlock(&dpy->Mutex);
}
@@ -896,7 +898,7 @@ eglWaitClient(void)
RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display;
- _eglLockMutex(&disp->Mutex);
+ mtx_lock(&disp->Mutex);
/* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
@@ -942,7 +944,7 @@ eglWaitNative(EGLint engine)
RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display;
- _eglLockMutex(&disp->Mutex);
+ mtx_lock(&disp->Mutex);
/* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
@@ -1457,10 +1459,10 @@ eglReleaseThread(void)
t->CurrentAPIIndex = i;
- _eglLockMutex(&disp->Mutex);
+ mtx_lock(&disp->Mutex);
drv = disp->Driver;
(void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
- _eglUnlockMutex(&disp->Mutex);
+ mtx_unlock(&disp->Mutex);
}
}
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index 3d496411cbb..dc32ed4c210 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -31,7 +31,6 @@
#include "c99_compat.h"
#include "egllog.h"
-#include "eglmutex.h"
#include "eglcurrent.h"
#include "eglglobals.h"
@@ -47,7 +46,7 @@ static _EGLThreadInfo dummy_thread = _EGL_THREAD_INFO_INITIALIZER;
#if HAVE_PTHREAD
#include <pthread.h>
-static _EGLMutex _egl_TSDMutex = _EGL_MUTEX_INITIALIZER;
+static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP;
static EGLBoolean _egl_TSDInitialized;
static pthread_key_t _egl_TSD;
static void (*_egl_FreeTSD)(_EGLThreadInfo *);
@@ -76,7 +75,7 @@ static inline _EGLThreadInfo *_eglGetTSD(void)
static inline void _eglFiniTSD(void)
{
- _eglLockMutex(&_egl_TSDMutex);
+ mtx_lock(&_egl_TSDMutex);
if (_egl_TSDInitialized) {
_EGLThreadInfo *t = _eglGetTSD();
@@ -85,18 +84,18 @@ static inline void _eglFiniTSD(void)
_egl_FreeTSD((void *) t);
pthread_key_delete(_egl_TSD);
}
- _eglUnlockMutex(&_egl_TSDMutex);
+ mtx_unlock(&_egl_TSDMutex);
}
static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
{
if (!_egl_TSDInitialized) {
- _eglLockMutex(&_egl_TSDMutex);
+ mtx_lock(&_egl_TSDMutex);
/* check again after acquiring lock */
if (!_egl_TSDInitialized) {
if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) {
- _eglUnlockMutex(&_egl_TSDMutex);
+ mtx_unlock(&_egl_TSDMutex);
return EGL_FALSE;
}
_egl_FreeTSD = dtor;
@@ -104,7 +103,7 @@ static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
_egl_TSDInitialized = EGL_TRUE;
}
- _eglUnlockMutex(&_egl_TSDMutex);
+ mtx_unlock(&_egl_TSDMutex);
}
return EGL_TRUE;
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index a167ae5c738..b7a5b8fb9d9 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -35,13 +35,14 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include "c11/threads.h"
+
#include "eglcontext.h"
#include "eglcurrent.h"
#include "eglsurface.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "eglglobals.h"
-#include "eglmutex.h"
#include "egllog.h"
/* Includes for _eglNativePlatformDetectNativeDisplay */
@@ -260,7 +261,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
if (plat == _EGL_INVALID_PLATFORM)
return NULL;
- _eglLockMutex(_eglGlobal.Mutex);
+ mtx_lock(_eglGlobal.Mutex);
/* search the display list first */
dpy = _eglGlobal.DisplayList;
@@ -274,7 +275,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
if (!dpy) {
dpy = calloc(1, sizeof(_EGLDisplay));
if (dpy) {
- _eglInitMutex(&dpy->Mutex);
+ mtx_init(&dpy->Mutex, mtx_plain);
dpy->Platform = plat;
dpy->PlatformDisplay = plat_dpy;
@@ -284,7 +285,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
}
}
- _eglUnlockMutex(_eglGlobal.Mutex);
+ mtx_unlock(_eglGlobal.Mutex);
return dpy;
}
@@ -344,14 +345,14 @@ _eglCheckDisplayHandle(EGLDisplay dpy)
{
_EGLDisplay *cur;
- _eglLockMutex(_eglGlobal.Mutex);
+ mtx_lock(_eglGlobal.Mutex);
cur = _eglGlobal.DisplayList;
while (cur) {
if (cur == (_EGLDisplay *) dpy)
break;
cur = cur->Next;
}
- _eglUnlockMutex(_eglGlobal.Mutex);
+ mtx_unlock(_eglGlobal.Mutex);
return (cur != NULL);
}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 9c3c8c7cf16..5a845d89962 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -32,10 +32,10 @@
#define EGLDISPLAY_INCLUDED
#include "c99_compat.h"
+#include "c11/threads.h"
#include "egltypedefs.h"
#include "egldefines.h"
-#include "eglmutex.h"
#include "eglarray.h"
@@ -132,7 +132,7 @@ struct _egl_display
/* used to link displays */
_EGLDisplay *Next;
- _EGLMutex Mutex;
+ mtx_t Mutex;
_EGLPlatformType Platform; /**< The type of the platform display */
void *PlatformDisplay; /**< A pointer to the platform display */
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index e6a61f3108b..6983af966b6 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -37,13 +37,13 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include "c11/threads.h"
#include "eglstring.h"
#include "egldefines.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "egllog.h"
-#include "eglmutex.h"
#if defined(_EGL_OS_UNIX)
#include <dlfcn.h>
@@ -63,7 +63,7 @@ typedef struct _egl_module {
_EGLDriver *Driver;
} _EGLModule;
-static _EGLMutex _eglModuleMutex = _EGL_MUTEX_INITIALIZER;
+static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP;
static _EGLArray *_eglModules;
const struct {
@@ -616,7 +616,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
assert(!dpy->Initialized);
- _eglLockMutex(&_eglModuleMutex);
+ mtx_lock(&_eglModuleMutex);
/* set options */
dpy->Options.TestOnly = test_only;
@@ -628,7 +628,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
best_drv = _eglMatchAndInitialize(dpy);
}
- _eglUnlockMutex(&_eglModuleMutex);
+ mtx_unlock(&_eglModuleMutex);
if (best_drv) {
_eglLog(_EGL_DEBUG, "the best driver is %s%s",
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 56fe9e29d8b..129bf29f1e9 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -30,13 +30,14 @@
#include <stdlib.h>
#include <assert.h>
+#include "c11/threads.h"
+
#include "eglglobals.h"
#include "egldisplay.h"
#include "egldriver.h"
-#include "eglmutex.h"
-static _EGLMutex _eglGlobalMutex = _EGL_MUTEX_INITIALIZER;
+static mtx_t _eglGlobalMutex = _MTX_INITIALIZER_NP;
struct _egl_global _eglGlobal =
{
@@ -84,7 +85,7 @@ _eglAddAtExitCall(void (*func)(void))
if (func) {
static EGLBoolean registered = EGL_FALSE;
- _eglLockMutex(_eglGlobal.Mutex);
+ mtx_lock(_eglGlobal.Mutex);
if (!registered) {
atexit(_eglAtExit);
@@ -94,6 +95,6 @@ _eglAddAtExitCall(void (*func)(void))
assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
_eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
- _eglUnlockMutex(_eglGlobal.Mutex);
+ mtx_unlock(_eglGlobal.Mutex);
}
}
diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h
index a8cf6d69124..04b96099a3b 100644
--- a/src/egl/main/eglglobals.h
+++ b/src/egl/main/eglglobals.h
@@ -32,9 +32,9 @@
#define EGLGLOBALS_INCLUDED
#include <stdbool.h>
+#include "c11/threads.h"
#include "egltypedefs.h"
-#include "eglmutex.h"
/**
@@ -42,7 +42,7 @@
*/
struct _egl_global
{
- _EGLMutex *Mutex;
+ mtx_t *Mutex;
/* the list of all displays */
_EGLDisplay *DisplayList;
diff --git a/src/egl/main/egllog.c b/src/egl/main/egllog.c
index babab07d8eb..1877d8bfd10 100644
--- a/src/egl/main/egllog.c
+++ b/src/egl/main/egllog.c
@@ -38,24 +38,24 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include "c11/threads.h"
#include "egllog.h"
#include "eglstring.h"
-#include "eglmutex.h"
#define MAXSTRING 1000
#define FALLBACK_LOG_LEVEL _EGL_WARNING
static struct {
- _EGLMutex mutex;
+ mtx_t mutex;
EGLBoolean initialized;
EGLint level;
_EGLLogProc logger;
EGLint num_messages;
} logging = {
- _EGL_MUTEX_INITIALIZER,
+ _MTX_INITIALIZER_NP,
EGL_FALSE,
FALLBACK_LOG_LEVEL,
NULL,
@@ -82,7 +82,7 @@ _eglSetLogProc(_EGLLogProc logger)
{
EGLint num_messages = 0;
- _eglLockMutex(&logging.mutex);
+ mtx_lock(&logging.mutex);
if (logging.logger != logger) {
logging.logger = logger;
@@ -91,7 +91,7 @@ _eglSetLogProc(_EGLLogProc logger)
logging.num_messages = 0;
}
- _eglUnlockMutex(&logging.mutex);
+ mtx_unlock(&logging.mutex);
if (num_messages)
_eglLog(_EGL_DEBUG,
@@ -111,9 +111,9 @@ _eglSetLogLevel(EGLint level)
case _EGL_WARNING:
case _EGL_INFO:
case _EGL_DEBUG:
- _eglLockMutex(&logging.mutex);
+ mtx_lock(&logging.mutex);
logging.level = level;
- _eglUnlockMutex(&logging.mutex);
+ mtx_unlock(&logging.mutex);
break;
default:
break;
@@ -188,7 +188,7 @@ _eglLog(EGLint level, const char *fmtStr, ...)
if (level > logging.level || level < 0)
return;
- _eglLockMutex(&logging.mutex);
+ mtx_lock(&logging.mutex);
if (logging.logger) {
va_start(args, fmtStr);
@@ -201,7 +201,7 @@ _eglLog(EGLint level, const char *fmtStr, ...)
logging.num_messages++;
}
- _eglUnlockMutex(&logging.mutex);
+ mtx_unlock(&logging.mutex);
if (level == _EGL_FATAL)
exit(1); /* or abort()? */
diff --git a/src/egl/main/eglmutex.h b/src/egl/main/eglmutex.h
deleted file mode 100644
index b58f0e3faef..00000000000
--- a/src/egl/main/eglmutex.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**************************************************************************
- *
- * 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 */
diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c
index b8f2b39c7b9..42ac621fcd9 100644
--- a/src/egl/main/eglscreen.c
+++ b/src/egl/main/eglscreen.c
@@ -44,20 +44,20 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include "c11/threads.h"
#include "egldisplay.h"
#include "eglcurrent.h"
#include "eglmode.h"
#include "eglsurface.h"
#include "eglscreen.h"
-#include "eglmutex.h"
#ifdef EGL_MESA_screen_surface
/* ugh, no atomic op? */
-static _EGLMutex _eglNextScreenHandleMutex = _EGL_MUTEX_INITIALIZER;
+static mtx_t _eglNextScreenHandleMutex = _MTX_INITIALIZER_NP;
static EGLScreenMESA _eglNextScreenHandle = 1;
@@ -70,10 +70,10 @@ _eglAllocScreenHandle(void)
{
EGLScreenMESA s;
- _eglLockMutex(&_eglNextScreenHandleMutex);
+ mtx_lock(&_eglNextScreenHandleMutex);
s = _eglNextScreenHandle;
_eglNextScreenHandle += _EGL_SCREEN_MAX_MODES;
- _eglUnlockMutex(&_eglNextScreenHandleMutex);
+ mtx_unlock(&_eglNextScreenHandleMutex);
return s;
}