Commit 1302a4ba by Ben Clayton

Vulkan/Debug: Assert on locking context twice on same thread

TSAN will catch this, but when its disabled, everything simply freezes and you have to go hunting across all the threads in the debugger. Just explode immediately with a sensible message. Bug: b/145351270 Change-Id: Iecef77a47bd54daabb489c5ca70e44b68c0c1e1f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48692 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent bb4045bc
...@@ -26,8 +26,18 @@ ...@@ -26,8 +26,18 @@
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
# define CHECK_REENTRANT_CONTEXT_LOCKS 1
#else
# define CHECK_REENTRANT_CONTEXT_LOCKS 0
#endif
namespace { namespace {
#if CHECK_REENTRANT_CONTEXT_LOCKS
thread_local std::unordered_set<const void *> contextsWithLock;
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Broadcaster - template base class for ServerEventBroadcaster and // Broadcaster - template base class for ServerEventBroadcaster and
// ClientEventBroadcaster // ClientEventBroadcaster
...@@ -244,6 +254,10 @@ std::shared_ptr<Context> Context::create() ...@@ -244,6 +254,10 @@ std::shared_ptr<Context> Context::create()
Context::Lock::Lock(Impl *ctx) Context::Lock::Lock(Impl *ctx)
: ctx(ctx) : ctx(ctx)
{ {
#if CHECK_REENTRANT_CONTEXT_LOCKS
ASSERT_MSG(contextsWithLock.count(ctx) == 0, "Attempting to acquire Context lock twice on same thread. This will deadlock");
contextsWithLock.emplace(ctx);
#endif
ctx->mutex.lock(); ctx->mutex.lock();
} }
...@@ -269,6 +283,10 @@ void Context::Lock::unlock() ...@@ -269,6 +283,10 @@ void Context::Lock::unlock()
{ {
if(ctx) if(ctx)
{ {
#if CHECK_REENTRANT_CONTEXT_LOCKS
contextsWithLock.erase(ctx);
#endif
ctx->mutex.unlock(); ctx->mutex.unlock();
ctx = nullptr; ctx = nullptr;
} }
......
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