1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Replaced incorrect double checked locking with a static

Thread Sanitizer identified an incorrect implementation of double checked locking.

Replaced it with a static, which therefore can only be created once.
This commit is contained in:
Sean McBride
2022-02-14 16:33:04 -05:00
parent 9f2ff3ed22
commit 5b23752205
+8 -12
View File
@@ -176,27 +176,23 @@ public:
}
};
namespace
static
MatAllocator*& getDefaultAllocatorMatRef()
{
MatAllocator* volatile g_matAllocator = NULL;
static MatAllocator* g_matAllocator = Mat::getStdAllocator();
return g_matAllocator;
}
MatAllocator* Mat::getDefaultAllocator()
{
if (g_matAllocator == NULL)
{
cv::AutoLock lock(cv::getInitializationMutex());
if (g_matAllocator == NULL)
{
g_matAllocator = getStdAllocator();
}
}
return g_matAllocator;
return getDefaultAllocatorMatRef();
}
void Mat::setDefaultAllocator(MatAllocator* allocator)
{
g_matAllocator = allocator;
getDefaultAllocatorMatRef() = allocator;
}
MatAllocator* Mat::getStdAllocator()
{
CV_SINGLETON_LAZY_INIT(MatAllocator, new StdMatAllocator())