summaryrefslogtreecommitdiff
path: root/src/egl/main/eglglobals.c
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2009-08-18 12:20:36 -0700
committerIan Romanick <ian.d.romanick@intel.com>2009-08-18 12:20:36 -0700
commita512985fd81c1ed4ccc5e69aaa05015cf7ff844d (patch)
tree69e6e898deaeaed2b4dfb5851707c68261c464de /src/egl/main/eglglobals.c
parent0b5af41c6fae2809f4567a7cecbd207e5e4f3ab5 (diff)
parentc80bc3abcd3939e5e2d45aea4b01ff22bfec244b (diff)
Merge branch 'master' into asm-shader-rework-1
Conflicts: src/mesa/shader/arbprogparse.c
Diffstat (limited to 'src/egl/main/eglglobals.c')
-rw-r--r--src/egl/main/eglglobals.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 55de394ef5..e93b48e03b 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -1,41 +1,53 @@
#include <stdlib.h>
+#include <assert.h>
#include "eglglobals.h"
+#include "egldisplay.h"
#include "egllog.h"
+#include "eglmutex.h"
-struct _egl_global _eglGlobal =
-{
- EGL_FALSE
-};
-/**
- * Init the fields in the _eglGlobal struct
- * May be safely called more than once.
- */
-void
-_eglInitGlobals(void)
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+
+static _EGL_DECLARE_MUTEX(_eglGlobalMutex);
+struct _egl_global _eglGlobal =
{
- if (!_eglGlobal.Initialized) {
- _eglGlobal.Displays = _eglNewHashTable();
- _eglGlobal.Surfaces = _eglNewHashTable();
- _eglGlobal.FreeScreenHandle = 1;
- _eglGlobal.Initialized = EGL_TRUE;
+ &_eglGlobalMutex, /* Mutex */
+ 1, /* FreeScreenHandle */
+ 0x0, /* ClientAPIsMask */
+ { 0x0 }, /* ClientAPIs */
+ 0, /* NumDrivers */
+ { NULL }, /* Drivers */
+ 0, /* NumAtExitCalls */
+ { NULL }, /* AtExitCalls */
+};
- _eglGlobal.ClientAPIsMask = 0x0;
- if (!_eglInitCurrent())
- _eglLog(_EGL_FATAL, "failed to initialize \"current\" system");
- }
+static void
+_eglAtExit(void)
+{
+ EGLint i;
+ for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--)
+ _eglGlobal.AtExitCalls[i]();
}
-/**
- * Should call this via an atexit handler.
- */
void
-_eglDestroyGlobals(void)
+_eglAddAtExitCall(void (*func)(void))
{
- _eglFiniCurrent();
- /* XXX TODO walk over table entries, deleting each */
- _eglDeleteHashTable(_eglGlobal.Displays);
- _eglDeleteHashTable(_eglGlobal.Surfaces);
+ if (func) {
+ static EGLBoolean registered = EGL_FALSE;
+
+ _eglLockMutex(_eglGlobal.Mutex);
+
+ if (!registered) {
+ atexit(_eglAtExit);
+ registered = EGL_TRUE;
+ }
+
+ assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
+ _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
+
+ _eglUnlockMutex(_eglGlobal.Mutex);
+ }
}