summaryrefslogtreecommitdiff
path: root/src/egl/main/eglglobals.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/egl/main/eglglobals.c')
-rw-r--r--src/egl/main/eglglobals.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
new file mode 100644
index 0000000000..e63819e08a
--- /dev/null
+++ b/src/egl/main/eglglobals.c
@@ -0,0 +1,53 @@
+#include <stdlib.h>
+#include <assert.h>
+#include "eglglobals.h"
+#include "egldisplay.h"
+#include "egldriver.h"
+#include "eglmutex.h"
+
+
+static _EGL_DECLARE_MUTEX(_eglGlobalMutex);
+struct _egl_global _eglGlobal =
+{
+ &_eglGlobalMutex, /* Mutex */
+ NULL, /* DisplayList */
+ 1, /* FreeScreenHandle */
+ 0, /* NumDrivers */
+ { NULL }, /* Drivers */
+ 2, /* NumAtExitCalls */
+ {
+ /* default AtExitCalls, called in reverse order */
+ _eglUnloadDrivers, /* always called last */
+ _eglFiniDisplay
+ },
+};
+
+
+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);
+ }
+}