Commit d650efc0 authored by Alexander Alekhin's avatar Alexander Alekhin

ocl: multi-threading: opencl buffer memory guard

parent 96a4a7b3
...@@ -192,6 +192,7 @@ void openCLMallocPitchEx(Context *ctx, void **dev_ptr, size_t *pitch, ...@@ -192,6 +192,7 @@ void openCLMallocPitchEx(Context *ctx, void **dev_ptr, size_t *pitch,
clFinish(getClCommandQueue(ctx)); clFinish(getClCommandQueue(ctx));
#endif #endif
CheckBuffers data(mainBuffer, size, widthInBytes, height); CheckBuffers data(mainBuffer, size, widthInBytes, height);
cv::AutoLock lock(getInitializationMutex());
__check_buffers.insert(std::pair<cl_mem, CheckBuffers>((cl_mem)*dev_ptr, data)); __check_buffers.insert(std::pair<cl_mem, CheckBuffers>((cl_mem)*dev_ptr, data));
} }
#endif #endif
...@@ -253,10 +254,17 @@ void openCLFree(void *devPtr) ...@@ -253,10 +254,17 @@ void openCLFree(void *devPtr)
bool failBefore = false, failAfter = false; bool failBefore = false, failAfter = false;
#endif #endif
CheckBuffers data; CheckBuffers data;
std::map<cl_mem, CheckBuffers>::iterator i = __check_buffers.find((cl_mem)devPtr);
if (i != __check_buffers.end())
{ {
data = i->second; cv::AutoLock lock(getInitializationMutex());
std::map<cl_mem, CheckBuffers>::iterator i = __check_buffers.find((cl_mem)devPtr);
if (i != __check_buffers.end())
{
data = i->second;
__check_buffers.erase(i);
}
}
if (data.mainBuffer != NULL)
{
#ifdef CHECK_MEMORY_CORRUPTION #ifdef CHECK_MEMORY_CORRUPTION
Context* ctx = Context::getContext(); Context* ctx = Context::getContext();
std::vector<uchar> checkBefore(__memory_corruption_guard_bytes); std::vector<uchar> checkBefore(__memory_corruption_guard_bytes);
...@@ -286,7 +294,6 @@ void openCLFree(void *devPtr) ...@@ -286,7 +294,6 @@ void openCLFree(void *devPtr)
clFinish(getClCommandQueue(ctx)); clFinish(getClCommandQueue(ctx));
#endif #endif
openCLSafeCall(clReleaseMemObject(data.mainBuffer)); openCLSafeCall(clReleaseMemObject(data.mainBuffer));
__check_buffers.erase(i);
} }
#if defined(CHECK_MEMORY_CORRUPTION) #if defined(CHECK_MEMORY_CORRUPTION)
if (failBefore) if (failBefore)
......
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