From 5fd724b54a1143bed2d3aa0ff8f5a1ec0bc61e30 Mon Sep 17 00:00:00 2001 From: peng xiao Date: Thu, 13 Jun 2013 10:46:12 +0800 Subject: [PATCH] Add a function to query if global OpenCL context is initialized. --- modules/ocl/include/opencv2/ocl/ocl.hpp | 5 ++++- modules/ocl/src/initialization.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/ocl/include/opencv2/ocl/ocl.hpp b/modules/ocl/include/opencv2/ocl/ocl.hpp index 4a5debf..2902127 100644 --- a/modules/ocl/include/opencv2/ocl/ocl.hpp +++ b/modules/ocl/include/opencv2/ocl/ocl.hpp @@ -134,6 +134,9 @@ namespace cv //getDevice also need to be called before this function CV_EXPORTS void setDeviceEx(Info &oclinfo, void *ctx, void *qu, int devnum = 0); + //returns true when global OpenCL context is initialized + CV_EXPORTS bool initialized(); + //////////////////////////////// Error handling //////////////////////// CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func); @@ -144,7 +147,7 @@ namespace cv protected: Context(); friend class auto_ptr; - + friend bool initialized(); private: static auto_ptr clCxt; static int val; diff --git a/modules/ocl/src/initialization.cpp b/modules/ocl/src/initialization.cpp index a9cd08b..78a9567 100644 --- a/modules/ocl/src/initialization.cpp +++ b/modules/ocl/src/initialization.cpp @@ -917,6 +917,14 @@ namespace cv int Context::val = 0; static Mutex cs; static volatile int context_tear_down = 0; + + bool initialized() + { + return *((volatile int*)&Context::val) != 0 && + Context::clCxt->impl->clCmdQueue != NULL&& + Context::clCxt->impl->oclcontext != NULL; + } + Context* Context::getContext() { if(*((volatile int*)&val) != 1) -- 2.7.4