OSDN Git Service

Add a mutex around SyncSet operations
authorGreg Hartman <ghartman@google.com>
Fri, 26 Aug 2016 03:18:01 +0000 (20:18 -0700)
committerNicolas Capens <capn@google.com>
Mon, 23 Jan 2017 16:26:28 +0000 (16:26 +0000)
BUG: 31072273
Change-Id: I037505ad3ab1ba80aecab4e24ec8d1932df2dcf7
Reviewed-on: https://swiftshader-review.googlesource.com/7030
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
src/OpenGL/libEGL/Display.cpp
src/OpenGL/libEGL/Display.h

index 270c8fa..31be0e9 100644 (file)
 #include <vector>
 #include <map>
 
+class Guard
+{
+public:
+       explicit Guard(sw::BackoffLock* in) : mMutex(in)
+       {
+               mMutex->lock();
+       }
+
+       ~Guard()
+       {
+               mMutex->unlock();
+       }
+protected:
+       sw::BackoffLock* mMutex;
+};
+
 namespace egl
 {
 
@@ -453,9 +469,8 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh
 EGLSyncKHR Display::createSync(Context *context)
 {
        FenceSync *fenceSync = new egl::FenceSync(context);
-
+       Guard lk(&mSyncSetMutex);
        mSyncSet.insert(fenceSync);
-
        return fenceSync;
 }
 
@@ -490,8 +505,10 @@ void Display::destroyContext(egl::Context *context)
 
 void Display::destroySync(FenceSync *sync)
 {
-       mSyncSet.erase(sync);
-
+       {
+               Guard lk(&mSyncSetMutex);
+               mSyncSet.erase(sync);
+       }
        delete sync;
 }
 
@@ -566,6 +583,7 @@ bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
 
 bool Display::isValidSync(FenceSync *sync)
 {
+       Guard lk(&mSyncSetMutex);
        return mSyncSet.find(sync) != mSyncSet.end();
 }
 
index acd639a..96e1453 100644 (file)
@@ -20,6 +20,7 @@
 #define INCLUDE_DISPLAY_H_
 
 #include "Config.h"
+#include "Common/MutexLock.hpp"
 #include "Sync.hpp"
 #include "common/NameSpace.hpp"
 
@@ -91,6 +92,7 @@ namespace egl
                ContextSet mContextSet;
 
                typedef std::set<FenceSync*> SyncSet;
+               sw::BackoffLock mSyncSetMutex;
                SyncSet mSyncSet;
 
                gl::NameSpace<Image> mSharedImageNameSpace;