Commit e90e398e authored by Alexander Alekhin's avatar Alexander Alekhin

core(ocl): do not split refcount operations / compare

- check result from CV_XADD() directly
- decrease urefcount after unmap() call only
parent 2f0fc920
...@@ -84,14 +84,11 @@ UMatData::~UMatData() ...@@ -84,14 +84,11 @@ UMatData::~UMatData()
allocatorFlags_ = 0; allocatorFlags_ = 0;
if (originalUMatData) if (originalUMatData)
{ {
UMatData* u = originalUMatData;
CV_XADD(&(u->urefcount), -1);
CV_XADD(&(u->refcount), -1);
bool showWarn = false; bool showWarn = false;
if (u->refcount == 0) UMatData* u = originalUMatData;
bool zero_Ref = CV_XADD(&(u->refcount), -1) == 1;
if (zero_Ref)
{ {
if (u->urefcount > 0)
showWarn = true;
// simulate Mat::deallocate // simulate Mat::deallocate
if (u->mapcount != 0) if (u->mapcount != 0)
{ {
...@@ -102,7 +99,10 @@ UMatData::~UMatData() ...@@ -102,7 +99,10 @@ UMatData::~UMatData()
// we don't do "map", so we can't do "unmap" // we don't do "map", so we can't do "unmap"
} }
} }
if (u->refcount == 0 && u->urefcount == 0) // oops, we need to free resources bool zero_URef = CV_XADD(&(u->urefcount), -1) == 1;
if (zero_Ref && !zero_URef)
showWarn = true;
if (zero_Ref && zero_URef) // oops, we need to free resources
{ {
showWarn = true; showWarn = true;
// simulate UMat::deallocate // simulate UMat::deallocate
......
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