eglmisc.h \
eglmode.c \
eglmode.h \
+ eglmutex.h \
eglscreen.c \
eglscreen.h \
eglstring.c \
#include <stdlib.h>
#include <string.h>
#include "c99_compat.h"
-#include "c11/threads.h"
-#include "eglcompiler.h"
#include "eglglobals.h"
#include "eglcontext.h"
{
_EGLDisplay *dpy = _eglLookupDisplay(display);
if (dpy)
- mtx_lock(&dpy->Mutex);
+ _eglLockMutex(&dpy->Mutex);
return dpy;
}
static inline void
_eglUnlockDisplay(_EGLDisplay *dpy)
{
- mtx_unlock(&dpy->Mutex);
+ _eglUnlockMutex(&dpy->Mutex);
}
RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display;
- mtx_lock(&disp->Mutex);
+ _eglLockMutex(&disp->Mutex);
/* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
disp = ctx->Resource.Display;
- mtx_lock(&disp->Mutex);
+ _eglLockMutex(&disp->Mutex);
/* let bad current context imply bad current surface */
if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
t->CurrentAPIIndex = i;
- mtx_lock(&disp->Mutex);
+ _eglLockMutex(&disp->Mutex);
drv = disp->Driver;
(void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
- mtx_unlock(&disp->Mutex);
+ _eglUnlockMutex(&disp->Mutex);
}
}
#include "c99_compat.h"
#include "egllog.h"
+#include "eglmutex.h"
#include "eglcurrent.h"
#include "eglglobals.h"
#if HAVE_PTHREAD
#include <pthread.h>
-static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP;
+static _EGLMutex _egl_TSDMutex = _EGL_MUTEX_INITIALIZER;
static EGLBoolean _egl_TSDInitialized;
static pthread_key_t _egl_TSD;
static void (*_egl_FreeTSD)(_EGLThreadInfo *);
static inline void _eglFiniTSD(void)
{
- mtx_lock(&_egl_TSDMutex);
+ _eglLockMutex(&_egl_TSDMutex);
if (_egl_TSDInitialized) {
_EGLThreadInfo *t = _eglGetTSD();
_egl_FreeTSD((void *) t);
pthread_key_delete(_egl_TSD);
}
- mtx_unlock(&_egl_TSDMutex);
+ _eglUnlockMutex(&_egl_TSDMutex);
}
static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
{
if (!_egl_TSDInitialized) {
- mtx_lock(&_egl_TSDMutex);
+ _eglLockMutex(&_egl_TSDMutex);
/* check again after acquiring lock */
if (!_egl_TSDInitialized) {
if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) {
- mtx_unlock(&_egl_TSDMutex);
+ _eglUnlockMutex(&_egl_TSDMutex);
return EGL_FALSE;
}
_egl_FreeTSD = dtor;
_egl_TSDInitialized = EGL_TRUE;
}
- mtx_unlock(&_egl_TSDMutex);
+ _eglUnlockMutex(&_egl_TSDMutex);
}
return EGL_TRUE;
#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 */
if (plat == _EGL_INVALID_PLATFORM)
return NULL;
- mtx_lock(_eglGlobal.Mutex);
+ _eglLockMutex(_eglGlobal.Mutex);
/* search the display list first */
dpy = _eglGlobal.DisplayList;
if (!dpy) {
dpy = calloc(1, sizeof(_EGLDisplay));
if (dpy) {
- mtx_init(&dpy->Mutex, mtx_plain);
+ _eglInitMutex(&dpy->Mutex);
dpy->Platform = plat;
dpy->PlatformDisplay = plat_dpy;
}
}
- mtx_unlock(_eglGlobal.Mutex);
+ _eglUnlockMutex(_eglGlobal.Mutex);
return dpy;
}
{
_EGLDisplay *cur;
- mtx_lock(_eglGlobal.Mutex);
+ _eglLockMutex(_eglGlobal.Mutex);
cur = _eglGlobal.DisplayList;
while (cur) {
if (cur == (_EGLDisplay *) dpy)
break;
cur = cur->Next;
}
- mtx_unlock(_eglGlobal.Mutex);
+ _eglUnlockMutex(_eglGlobal.Mutex);
return (cur != NULL);
}
#define EGLDISPLAY_INCLUDED
#include "c99_compat.h"
-#include "c11/threads.h"
#include "egltypedefs.h"
#include "egldefines.h"
+#include "eglmutex.h"
#include "eglarray.h"
/* used to link displays */
_EGLDisplay *Next;
- mtx_t Mutex;
+ _EGLMutex Mutex;
_EGLPlatformType Platform; /**< The type of the platform display */
void *PlatformDisplay; /**< A pointer to the platform display */
#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>
_EGLDriver *Driver;
} _EGLModule;
-static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP;
+static _EGLMutex _eglModuleMutex = _EGL_MUTEX_INITIALIZER;
static _EGLArray *_eglModules;
const struct {
assert(!dpy->Initialized);
- mtx_lock(&_eglModuleMutex);
+ _eglLockMutex(&_eglModuleMutex);
/* set options */
dpy->Options.TestOnly = test_only;
best_drv = _eglMatchAndInitialize(dpy);
}
- mtx_unlock(&_eglModuleMutex);
+ _eglUnlockMutex(&_eglModuleMutex);
if (best_drv) {
_eglLog(_EGL_DEBUG, "the best driver is %s%s",
#include <stdlib.h>
#include <assert.h>
-#include "c11/threads.h"
-
#include "eglglobals.h"
#include "egldisplay.h"
#include "egldriver.h"
+#include "eglmutex.h"
-static mtx_t _eglGlobalMutex = _MTX_INITIALIZER_NP;
+static _EGLMutex _eglGlobalMutex = _EGL_MUTEX_INITIALIZER;
struct _egl_global _eglGlobal =
{
if (func) {
static EGLBoolean registered = EGL_FALSE;
- mtx_lock(_eglGlobal.Mutex);
+ _eglLockMutex(_eglGlobal.Mutex);
if (!registered) {
atexit(_eglAtExit);
assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
_eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
- mtx_unlock(_eglGlobal.Mutex);
+ _eglUnlockMutex(_eglGlobal.Mutex);
}
}
#define EGLGLOBALS_INCLUDED
#include <stdbool.h>
-#include "c11/threads.h"
#include "egltypedefs.h"
+#include "eglmutex.h"
/**
*/
struct _egl_global
{
- mtx_t *Mutex;
+ _EGLMutex *Mutex;
/* the list of all displays */
_EGLDisplay *DisplayList;
#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 {
- mtx_t mutex;
+ _EGLMutex mutex;
EGLBoolean initialized;
EGLint level;
_EGLLogProc logger;
EGLint num_messages;
} logging = {
- _MTX_INITIALIZER_NP,
+ _EGL_MUTEX_INITIALIZER,
EGL_FALSE,
FALLBACK_LOG_LEVEL,
NULL,
{
EGLint num_messages = 0;
- mtx_lock(&logging.mutex);
+ _eglLockMutex(&logging.mutex);
if (logging.logger != logger) {
logging.logger = logger;
logging.num_messages = 0;
}
- mtx_unlock(&logging.mutex);
+ _eglUnlockMutex(&logging.mutex);
if (num_messages)
_eglLog(_EGL_DEBUG,
case _EGL_WARNING:
case _EGL_INFO:
case _EGL_DEBUG:
- mtx_lock(&logging.mutex);
+ _eglLockMutex(&logging.mutex);
logging.level = level;
- mtx_unlock(&logging.mutex);
+ _eglUnlockMutex(&logging.mutex);
break;
default:
break;
if (level > logging.level || level < 0)
return;
- mtx_lock(&logging.mutex);
+ _eglLockMutex(&logging.mutex);
if (logging.logger) {
va_start(args, fmtStr);
logging.num_messages++;
}
- mtx_unlock(&logging.mutex);
+ _eglUnlockMutex(&logging.mutex);
if (level == _EGL_FATAL)
exit(1); /* or abort()? */
--- /dev/null
+/**************************************************************************
+ *
+ * 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 */
#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 mtx_t _eglNextScreenHandleMutex = _MTX_INITIALIZER_NP;
+static _EGLMutex _eglNextScreenHandleMutex = _EGL_MUTEX_INITIALIZER;
static EGLScreenMESA _eglNextScreenHandle = 1;
{
EGLScreenMESA s;
- mtx_lock(&_eglNextScreenHandleMutex);
+ _eglLockMutex(&_eglNextScreenHandleMutex);
s = _eglNextScreenHandle;
_eglNextScreenHandle += _EGL_SCREEN_MAX_MODES;
- mtx_unlock(&_eglNextScreenHandleMutex);
+ _eglUnlockMutex(&_eglNextScreenHandleMutex);
return s;
}