summaryrefslogtreecommitdiffstats
path: root/src/egl/main/eglglobals.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2009-08-10 17:35:20 +0800
committerBrian Paul <[email protected]>2009-08-11 22:14:35 -0600
commit435c7ac24d8d6f8ddae59f4b66983d7642250d1e (patch)
tree1ff9c207c6ef065081a28a4844f64d1445c8dae7 /src/egl/main/eglglobals.c
parent0e3687e33dd482115c1a0e39c50b424936cb05a6 (diff)
egl: Add _eglAddAtExitCall.
Add a convenient wrapper to register atexit calls. Add mutex to _eglGlobal along the way. Signed-off-by: Chia-I Wu <[email protected]>
Diffstat (limited to 'src/egl/main/eglglobals.c')
-rw-r--r--src/egl/main/eglglobals.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 87031686500..e93b48e03b8 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -1,13 +1,53 @@
#include <stdlib.h>
+#include <assert.h>
#include "eglglobals.h"
#include "egldisplay.h"
#include "egllog.h"
+#include "eglmutex.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+
+static _EGL_DECLARE_MUTEX(_eglGlobalMutex);
struct _egl_global _eglGlobal =
{
+ &_eglGlobalMutex, /* Mutex */
1, /* FreeScreenHandle */
0x0, /* ClientAPIsMask */
{ 0x0 }, /* ClientAPIs */
0, /* NumDrivers */
{ NULL }, /* Drivers */
+ 0, /* NumAtExitCalls */
+ { NULL }, /* AtExitCalls */
};
+
+
+static void
+_eglAtExit(void)
+{
+ EGLint i;
+ for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--)
+ _eglGlobal.AtExitCalls[i]();
+}
+
+
+void
+_eglAddAtExitCall(void (*func)(void))
+{
+ 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);
+ }
+}