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>
namespace gl
{
#ifndef NDEBUG
namespace gl
{
#ifndef NDEBUG
+sw::MutexLock Object::instances_mutex;
std::set<Object*> Object::instances;
#endif
std::set<Object*> Object::instances;
#endif
referenceCount = 0;
#ifndef NDEBUG
referenceCount = 0;
#ifndef NDEBUG
+ LockGuard instances_lock(instances_mutex);
instances.insert(this);
#endif
}
instances.insert(this);
#endif
}
ASSERT(referenceCount == 0);
#ifndef NDEBUG
ASSERT(referenceCount == 0);
#ifndef NDEBUG
+ LockGuard instances_lock(instances_mutex);
ASSERT(instances.find(this) != instances.end()); // Check for double deletion
instances.erase(this);
#endif
ASSERT(instances.find(this) != instances.end()); // Check for double deletion
instances.erase(this);
#endif
+ LockGuard instances_lock(Object::instances_mutex);
ASSERT(Object::instances.empty()); // Check for GL object leak at termination
}
};
ASSERT(Object::instances.empty()); // Check for GL object leak at termination
}
};
#define gl_Object_hpp
#include "common/debug.h"
#define gl_Object_hpp
#include "common/debug.h"
+#include "Common/MutexLock.hpp"
+ static sw::MutexLock instances_mutex;
static std::set<Object*> instances; // For leak checking
#endif
};
static std::set<Object*> instances; // For leak checking
#endif
};