Commit ae518eb0 by Greg Hartman Committed by Nicolas Capens

Add a mutex around SyncSet operations

BUG: 31072273 Change-Id: I037505ad3ab1ba80aecab4e24ec8d1932df2dcf7 Reviewed-on: https://swiftshader-review.googlesource.com/7030Reviewed-by: 's avatarLingfeng Yang <lfy@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarLingfeng Yang <lfy@google.com>
parent 8b27574a
...@@ -40,6 +40,22 @@ ...@@ -40,6 +40,22 @@
#include <vector> #include <vector>
#include <map> #include <map>
class Guard
{
public:
explicit Guard(sw::BackoffLock* in) : mMutex(in)
{
mMutex->lock();
}
~Guard()
{
mMutex->unlock();
}
protected:
sw::BackoffLock* mMutex;
};
namespace egl namespace egl
{ {
...@@ -453,9 +469,8 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh ...@@ -453,9 +469,8 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh
EGLSyncKHR Display::createSync(Context *context) EGLSyncKHR Display::createSync(Context *context)
{ {
FenceSync *fenceSync = new egl::FenceSync(context); FenceSync *fenceSync = new egl::FenceSync(context);
Guard lk(&mSyncSetMutex);
mSyncSet.insert(fenceSync); mSyncSet.insert(fenceSync);
return fenceSync; return fenceSync;
} }
...@@ -490,8 +505,10 @@ void Display::destroyContext(egl::Context *context) ...@@ -490,8 +505,10 @@ void Display::destroyContext(egl::Context *context)
void Display::destroySync(FenceSync *sync) void Display::destroySync(FenceSync *sync)
{ {
mSyncSet.erase(sync); {
Guard lk(&mSyncSetMutex);
mSyncSet.erase(sync);
}
delete sync; delete sync;
} }
...@@ -566,6 +583,7 @@ bool Display::hasExistingWindowSurface(EGLNativeWindowType window) ...@@ -566,6 +583,7 @@ bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
bool Display::isValidSync(FenceSync *sync) bool Display::isValidSync(FenceSync *sync)
{ {
Guard lk(&mSyncSetMutex);
return mSyncSet.find(sync) != mSyncSet.end(); return mSyncSet.find(sync) != mSyncSet.end();
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define INCLUDE_DISPLAY_H_ #define INCLUDE_DISPLAY_H_
#include "Config.h" #include "Config.h"
#include "Common/MutexLock.hpp"
#include "Sync.hpp" #include "Sync.hpp"
#include "common/NameSpace.hpp" #include "common/NameSpace.hpp"
...@@ -91,6 +92,7 @@ namespace egl ...@@ -91,6 +92,7 @@ namespace egl
ContextSet mContextSet; ContextSet mContextSet;
typedef std::set<FenceSync*> SyncSet; typedef std::set<FenceSync*> SyncSet;
sw::BackoffLock mSyncSetMutex;
SyncSet mSyncSet; SyncSet mSyncSet;
gl::NameSpace<Image> mSharedImageNameSpace; gl::NameSpace<Image> mSharedImageNameSpace;
......
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