egl: Add _eglAddAtExitCall.
Add a convenient wrapper to register atexit calls. Add mutex to _eglGlobal along the way. Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
This commit is contained in:
parent
0e3687e33d
commit
435c7ac24d
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "egltypedefs.h"
|
||||
#include "eglhash.h"
|
||||
#include "eglcurrent.h"
|
||||
#include "eglmutex.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -11,6 +12,7 @@
|
|||
*/
|
||||
struct _egl_global
|
||||
{
|
||||
_EGLMutex *Mutex;
|
||||
EGLScreenMESA FreeScreenHandle;
|
||||
|
||||
/* bitmaks of supported APIs (supported by _some_ driver) */
|
||||
|
@ -20,10 +22,17 @@ struct _egl_global
|
|||
|
||||
EGLint NumDrivers;
|
||||
_EGLDriver *Drivers[10];
|
||||
|
||||
EGLint NumAtExitCalls;
|
||||
void (*AtExitCalls[10])(void);
|
||||
};
|
||||
|
||||
|
||||
extern struct _egl_global _eglGlobal;
|
||||
|
||||
|
||||
extern void
|
||||
_eglAddAtExitCall(void (*func)(void));
|
||||
|
||||
|
||||
#endif /* EGLGLOBALS_INCLUDED */
|
||||
|
|
Loading…
Reference in New Issue