Commit 8aac455e by Greg Hartman Committed by Nicolas Capens

Protect the displays global map

Bug 25597090 Change-Id: Ie6bc4f55b5105a3e75cdc1b636f3e5716c10cc61 Reviewed-on: https://swiftshader-review.googlesource.com/4240Tested-by: 's avatarGreg Hartman <ghartman@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent cbb8b399
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
#include "libEGL/Context.hpp" #include "libEGL/Context.hpp"
#include "common/debug.h" #include "common/debug.h"
#include "Common/MutexLock.hpp"
#if defined(__unix__) && !defined(__ANDROID__) #if defined(__unix__) && !defined(__ANDROID__)
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
...@@ -38,7 +39,17 @@ ...@@ -38,7 +39,17 @@
namespace egl namespace egl
{ {
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
DisplayMap displays;
// Protects the global displays map.
sw::BackoffLock displays_lock;
// The order of construction of globals is undefined in C++.
// This function ensures that construction has completed before we attempt
// to access displays.
DisplayMap* getDisplays() {
static DisplayMap displays;
return &displays;
}
egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId) egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId)
{ {
...@@ -81,15 +92,19 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType ...@@ -81,15 +92,19 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType
} }
#endif #endif
if(displays.find(displayId) != displays.end()) egl::Display *rval;
displays_lock.lock();
DisplayMap* displays = getDisplays();
if (displays->find(displayId) != displays->end())
{ {
return displays[displayId]; rval = (*displays)[displayId];
} } else {
rval = new egl::Display(platform, displayId);
egl::Display *display = new egl::Display(platform, displayId);
displays[displayId] = display; (*displays)[displayId] = rval;
return display; }
displays_lock.unlock();
return rval;
} }
Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(platform), displayId(displayId) Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(platform), displayId(displayId)
...@@ -102,7 +117,9 @@ Display::~Display() ...@@ -102,7 +117,9 @@ Display::~Display()
{ {
terminate(); terminate();
displays.erase(displayId); displays_lock.lock();
getDisplays()->erase(displayId);
displays_lock.unlock();
} }
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment