2006-01-30 00:10:55 +00:00
|
|
|
#include <stdlib.h>
|
2009-08-10 17:35:20 +08:00
|
|
|
#include <assert.h>
|
2005-04-22 21:09:39 +00:00
|
|
|
#include "eglglobals.h"
|
2009-08-13 13:01:48 +08:00
|
|
|
#include "egldriver.h"
|
2009-07-17 11:41:02 -06:00
|
|
|
#include "egllog.h"
|
2009-08-10 17:35:20 +08:00
|
|
|
#include "eglmutex.h"
|
2005-04-22 21:09:39 +00:00
|
|
|
|
2009-08-10 17:35:20 +08:00
|
|
|
|
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
|
|
|
|
|
|
|
|
static _EGL_DECLARE_MUTEX(_eglGlobalMutex);
|
2009-08-10 16:37:28 +08:00
|
|
|
struct _egl_global _eglGlobal =
|
2008-08-04 16:30:04 -06:00
|
|
|
{
|
2009-08-10 17:35:20 +08:00
|
|
|
&_eglGlobalMutex, /* Mutex */
|
2009-08-14 17:47:00 +08:00
|
|
|
NULL, /* DisplayList */
|
2009-08-10 16:37:28 +08:00
|
|
|
1, /* FreeScreenHandle */
|
|
|
|
0, /* NumDrivers */
|
|
|
|
{ NULL }, /* Drivers */
|
2009-08-14 17:47:00 +08:00
|
|
|
2, /* NumAtExitCalls */
|
2009-08-13 13:01:48 +08:00
|
|
|
{ /* AtExitCalls */
|
2009-08-14 17:47:00 +08:00
|
|
|
_eglFiniDisplay,
|
2009-08-13 13:01:48 +08:00
|
|
|
_eglUnloadDrivers
|
|
|
|
},
|
2008-08-04 16:30:04 -06:00
|
|
|
};
|
2009-08-10 17:35:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|