Commit 6b064940 by Ben Vanik Committed by Ben Vanik

Making debug object tracking thread safe.

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/10528Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Vanik <benvanik@google.com>
parent 1fd3b280
......@@ -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
}
};
......
......@@ -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
};
......
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