{
if( u && CV_XADD(&u->refcount, -1) == 1 )
deallocate();
+ u = NULL;
data = datastart = dataend = datalimit = 0;
size.p[0] = 0;
- u = 0;
}
inline
void MatAllocator::unmap(UMatData* u) const
{
if(u->urefcount == 0 && u->refcount == 0)
+ {
deallocate(u);
+ u = NULL;
+ }
}
void MatAllocator::download(UMatData* u, void* dstptr,
UMatData* u = new UMatData(this);
u->data = u->origdata = data;
u->size = total;
- u->refcount = data0 == 0;
if(data0)
u->flags |= UMatData::USER_ALLOCATED;
void deallocate(UMatData* u) const
{
+ CV_Assert(u->urefcount >= 0);
+ CV_Assert(u->refcount >= 0);
if(u && u->refcount == 0)
{
if( !(u->flags & UMatData::USER_ALLOCATED) )
CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) );
}
+ addref();
finalizeHdr(*this);
}
{
if(u)
(u->currAllocator ? u->currAllocator : allocator ? allocator : getStdAllocator())->unmap(u);
+ u = NULL;
}
Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange)
Impl(void* d)
{
handle = (cl_device_id)d;
+ refcount = 1;
}
template<typename _TpCL, typename _TpOut>
UMatData* defaultAllocate(int dims, const int* sizes, int type, void* data, size_t* step, int flags) const
{
UMatData* u = matStdAllocator->allocate(dims, sizes, type, data, step, flags);
- u->urefcount = 1;
- u->refcount = 0;
return u;
}
u->data = 0;
u->size = total;
u->handle = handle;
- u->urefcount = 1;
u->flags = flags0;
return u;
}
if(accessFlags & ACCESS_WRITE)
u->markHostCopyObsolete(true);
- CV_XADD(&u->urefcount, 1);
return true;
}
if(!u)
return;
+ CV_Assert(u->urefcount >= 0);
+ CV_Assert(u->refcount >= 0);
+
// TODO: !!! when we add Shared Virtual Memory Support,
// this function (as well as the others) should be corrected
CV_Assert(u->handle != 0 && u->urefcount == 0);
if(!a)
a = a0;
temp_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags);
+ temp_u->refcount = 1;
}
UMat::getStdAllocator()->allocate(temp_u, accessFlags);
hdr.flags = flags;
finalizeHdr(hdr);
hdr.u = temp_u;
hdr.offset = data - datastart;
+ hdr.addref();
return hdr;
}
}
finalizeHdr(*this);
+ addref();
}
void UMat::copySize(const UMat& m)
void UMat::deallocate()
{
u->currAllocator->deallocate(u);
+ u = NULL;
}