OSDN Git Service

Making debug object tracking thread safe.
authorBen Vanik <ben.vanik@gmail.com>
Mon, 10 Jul 2017 23:18:41 +0000 (16:18 -0700)
committerBen Vanik <benvanik@google.com>
Wed, 12 Jul 2017 14:58:22 +0000 (14:58 +0000)
Currently in debug builds swiftshader is not thread safe because of this
tracking code. This change makes it safe to create/delete objects from
multiple threads.

Change-Id: I9c8d3efc370687891b1acc786499bda02c86ad01
Reviewed-on: https://swiftshader-review.googlesource.com/10528
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Vanik <benvanik@google.com>
src/OpenGL/common/Object.cpp
src/OpenGL/common/Object.hpp

index 1a4a7c8..b4d84c0 100644 (file)
@@ -23,6 +23,7 @@
 namespace gl
 {
 #ifndef NDEBUG
+sw::MutexLock Object::instances_mutex;
 std::set<Object*> Object::instances;
 #endif
 
@@ -31,6 +32,7 @@ Object::Object()
        referenceCount = 0;
 
        #ifndef NDEBUG
+               LockGuard instances_lock(instances_mutex);
                instances.insert(this);
        #endif
 }
@@ -40,6 +42,7 @@ Object::~Object()
        ASSERT(referenceCount == 0);
 
        #ifndef NDEBUG
+               LockGuard instances_lock(instances_mutex);
                ASSERT(instances.find(this) != instances.end());   // Check for double deletion
                instances.erase(this);
        #endif
@@ -89,6 +92,7 @@ struct ObjectLeakCheck
 {
        ~ObjectLeakCheck()
        {
+               LockGuard instances_lock(Object::instances_mutex);
                ASSERT(Object::instances.empty());   // Check for GL object leak at termination
        }
 };
index c6243ac..7d9a8fe 100644 (file)
@@ -20,6 +20,7 @@
 #define gl_Object_hpp
 
 #include "common/debug.h"
+#include "Common/MutexLock.hpp"
 
 #include <set>
 
@@ -51,6 +52,7 @@ protected:
 
 #ifndef NDEBUG
 public:
+       static sw::MutexLock instances_mutex;
        static std::set<Object*> instances;   // For leak checking
 #endif
 };