Commit d39c96e9 by Cody Schuffelen

Create a recursive version of MutexLock, and apply it to EGL.

This fixes one deadlock in Android's use of SwiftShader. Now fixed for ASAN/tsan. Bug: b/124530765 Test: atest CtsGraphicsTestCases:android.graphics.cts.BitmapTest#testDrawingHardwareBitmapNotLeaking -- --abi x86 Test: b/124530765#comment53 Signed-off-by: 's avatarCody Schuffelen <schuffelen@google.com> Change-Id: Iacb04c0ac515eca1849d365c20efa84d58b75f72 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28308 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 90561c0e
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_RecursiveLock_hpp
#define sw_RecursiveLock_hpp
#include "Thread.hpp"
#include <mutex>
namespace sw
{
class RecursiveLock
{
public:
RecursiveLock()
{
}
bool attemptLock()
{
return mutex.try_lock();
}
void lock()
{
mutex.lock();
}
void unlock()
{
mutex.unlock();
}
private:
std::recursive_mutex mutex;
};
}
class RecursiveLockGuard
{
public:
explicit RecursiveLockGuard(sw::RecursiveLock &mutex) : mutex(&mutex)
{
mutex.lock();
}
explicit RecursiveLockGuard(sw::RecursiveLock *mutex) : mutex(mutex)
{
if (mutex) mutex->lock();
}
~RecursiveLockGuard()
{
if (mutex) mutex->unlock();
}
protected:
sw::RecursiveLock *mutex;
};
#endif // sw_RecursiveLock_hpp
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "libEGL/Context.hpp" #include "libEGL/Context.hpp"
#include "common/Image.hpp" #include "common/Image.hpp"
#include "common/debug.h" #include "common/debug.h"
#include "Common/MutexLock.hpp" #include "Common/RecursiveLock.hpp"
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <system/window.h> #include <system/window.h>
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#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/RecursiveLock.hpp"
#include "common/NameSpace.hpp" #include "common/NameSpace.hpp"
#include <set> #include <set>
...@@ -86,7 +86,7 @@ namespace egl ...@@ -86,7 +86,7 @@ namespace egl
bool destroySharedImage(EGLImageKHR); bool destroySharedImage(EGLImageKHR);
virtual Image *getSharedImage(EGLImageKHR name) = 0; virtual Image *getSharedImage(EGLImageKHR name) = 0;
sw::MutexLock *getLock() { return &mApiMutex; } sw::RecursiveLock *getLock() { return &mApiMutex; }
private: private:
sw::Format getDisplayFormat() const; sw::Format getDisplayFormat() const;
...@@ -109,7 +109,7 @@ namespace egl ...@@ -109,7 +109,7 @@ namespace egl
SyncSet mSyncSet; SyncSet mSyncSet;
gl::NameSpace<Image> mSharedImageNameSpace; gl::NameSpace<Image> mSharedImageNameSpace;
sw::MutexLock mApiMutex; sw::RecursiveLock mApiMutex;
}; };
} }
......
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