From: Chia-I Wu Date: Wed, 17 Feb 2010 11:03:30 +0000 (+0800) Subject: egl: Revisit global data locking. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4afe24808ee253c44c65b855f65bd0749c1e1524;p=mesa.git egl: Revisit global data locking. Lock the global mutex in _eglPreloadDrivers and _eglAllocScreenHandle. Add comments to why certain pathes do not need locking. --- diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index a87c697b113..8748fe5f467 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -237,6 +237,10 @@ _eglMatchDriver(_EGLDisplay *dpy) _EGLDriver *best_drv = NULL; EGLint best_score = -1, i; + /* + * this function is called after preloading and the drivers never change + * after preloading. + */ for (i = 0; i < _eglGlobal.NumDrivers; i++) { _EGLDriver *drv = _eglGlobal.Drivers[i]; EGLint score; @@ -529,14 +533,21 @@ _eglPreloadDrivers(void) { EGLBoolean loaded; + /* protect the preloading process */ + _eglLockMutex(_eglGlobal.Mutex); + /* already preloaded */ - if (_eglGlobal.NumDrivers) + if (_eglGlobal.NumDrivers) { + _eglUnlockMutex(_eglGlobal.Mutex); return EGL_TRUE; + } loaded = (_eglPreloadUserDriver() || _eglPreloadDisplayDrivers() || _eglPreloadDefaultDriver()); + _eglUnlockMutex(_eglGlobal.Mutex); + return loaded; } @@ -548,6 +559,8 @@ void _eglUnloadDrivers(void) { EGLint i; + + /* this is called at atexit time */ for (i = 0; i < _eglGlobal.NumDrivers; i++) { _EGLDriver *drv = _eglGlobal.Drivers[i]; lib_handle handle = drv->LibHandle; diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h index cd1dd5851b9..43688980208 100644 --- a/src/egl/main/eglglobals.h +++ b/src/egl/main/eglglobals.h @@ -18,6 +18,7 @@ struct _egl_global EGLScreenMESA FreeScreenHandle; + /* these never change after preloading */ EGLint NumDrivers; _EGLDriver *Drivers[10]; diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c index 97a405a4b4b..c47afd6abda 100644 --- a/src/egl/main/eglscreen.c +++ b/src/egl/main/eglscreen.c @@ -22,17 +22,22 @@ #include "eglconfig.h" #include "eglsurface.h" #include "eglscreen.h" +#include "eglmutex.h" /** * Return a new screen handle/ID. * NOTE: we never reuse these! */ -EGLScreenMESA +static EGLScreenMESA _eglAllocScreenHandle(void) { - EGLScreenMESA s = _eglGlobal.FreeScreenHandle; - _eglGlobal.FreeScreenHandle++; + EGLScreenMESA s; + + _eglLockMutex(_eglGlobal.Mutex); + s = _eglGlobal.FreeScreenHandle++; + _eglUnlockMutex(_eglGlobal.Mutex); + return s; } diff --git a/src/egl/main/eglscreen.h b/src/egl/main/eglscreen.h index c400ac3d15e..0fd71f71fc8 100644 --- a/src/egl/main/eglscreen.h +++ b/src/egl/main/eglscreen.h @@ -29,10 +29,6 @@ struct _egl_screen }; -extern EGLScreenMESA -_eglAllocScreenHandle(void); - - PUBLIC void _eglInitScreen(_EGLScreen *screen);