am d6fce7ab: Merge "Remove lock around ref count check in terminate." into lmp-mr1-dev

* commit 'd6fce7ab66e5d33e3ee16247485d1b8c26dd7ee8':
  Remove lock around ref count check in terminate.
This commit is contained in:
Michael Lentine 2015-01-28 22:38:42 +00:00 committed by Android Git Automerger
commit 2f1e3b4d21
2 changed files with 162 additions and 135 deletions

View File

@ -57,7 +57,7 @@ static bool findExtension(const char* exts, const char* name, size_t nameLen) {
egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS];
egl_display_t::egl_display_t() : egl_display_t::egl_display_t() :
magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0) { magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0), eglIsInitialized(false) {
} }
egl_display_t::~egl_display_t() { egl_display_t::~egl_display_t() {
@ -120,17 +120,25 @@ EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) {
EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
Mutex::Autolock _l(lock); {
Mutex::Autolock _rf(refLock);
if (refs > 0) { refs++;
if (refs > 1) {
if (major != NULL) if (major != NULL)
*major = VERSION_MAJOR; *major = VERSION_MAJOR;
if (minor != NULL) if (minor != NULL)
*minor = VERSION_MINOR; *minor = VERSION_MINOR;
refs++; while(!eglIsInitialized) refCond.wait(refLock);
return EGL_TRUE; return EGL_TRUE;
} }
while(eglIsInitialized) refCond.wait(refLock);
}
{
Mutex::Autolock _l(lock);
#if EGL_TRACE #if EGL_TRACE
// Called both at early_init time and at this time. (Early_init is pre-zygote, so // Called both at early_init time and at this time. (Early_init is pre-zygote, so
@ -214,21 +222,27 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
traceGpuCompletion = true; traceGpuCompletion = true;
} }
refs++;
if (major != NULL) if (major != NULL)
*major = VERSION_MAJOR; *major = VERSION_MAJOR;
if (minor != NULL) if (minor != NULL)
*minor = VERSION_MINOR; *minor = VERSION_MINOR;
mHibernation.setDisplayValid(true); mHibernation.setDisplayValid(true);
}
{
Mutex::Autolock _rf(refLock);
eglIsInitialized = true;
refCond.broadcast();
}
return EGL_TRUE; return EGL_TRUE;
} }
EGLBoolean egl_display_t::terminate() { EGLBoolean egl_display_t::terminate() {
Mutex::Autolock _l(lock); {
Mutex::Autolock _rl(refLock);
if (refs == 0) { if (refs == 0) {
/* /*
* From the EGL spec (3.2): * From the EGL spec (3.2):
@ -240,12 +254,17 @@ EGLBoolean egl_display_t::terminate() {
} }
// this is specific to Android, display termination is ref-counted. // this is specific to Android, display termination is ref-counted.
if (refs > 1) {
refs--; refs--;
if (refs > 0) {
return EGL_TRUE; return EGL_TRUE;
} }
}
EGLBoolean res = EGL_FALSE; EGLBoolean res = EGL_FALSE;
{
Mutex::Autolock _l(lock);
egl_connection_t* const cnx = &gEGLImpl; egl_connection_t* const cnx = &gEGLImpl;
if (cnx->dso && disp.state == egl_display_t::INITIALIZED) { if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) { if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
@ -275,8 +294,14 @@ EGLBoolean egl_display_t::terminate() {
// this marks all object handles are "terminated" // this marks all object handles are "terminated"
objects.clear(); objects.clear();
}
{
Mutex::Autolock _rl(refLock);
eglIsInitialized = false;
refCond.broadcast();
}
refs--;
return res; return res;
} }

View File

@ -131,7 +131,9 @@ private:
void leave() { return mHibernation.decWakeCount(HibernationMachine::WEAK); } void leave() { return mHibernation.decWakeCount(HibernationMachine::WEAK); }
uint32_t refs; uint32_t refs;
mutable Mutex lock; bool eglIsInitialized;
mutable Mutex lock, refLock;
mutable Condition refCond;
SortedVector<egl_object_t*> objects; SortedVector<egl_object_t*> objects;
String8 mVendorString; String8 mVendorString;
String8 mVersionString; String8 mVersionString;