From d72b5ccf595c682343e244cb338f2786165a5239 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 16 May 2020 14:59:58 +0100 Subject: [PATCH] Roll OsdOpenVG::haveOpenVGResponse into putOpenVGCommand --- osdopenvg.cc | 94 ++++++++++++++-------------------------------------- osdopenvg.h | 6 +++- 2 files changed, 29 insertions(+), 71 deletions(-) diff --git a/osdopenvg.cc b/osdopenvg.cc index 372e898..f1fa056 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -1367,7 +1367,7 @@ unsigned int OsdOpenVG::handleTask(OpenVGCommand& command) m->tag = info->lindex >> 32LL; } - MessageQueue::getInstance()->postMessage(m); // inform command about new picture + MessageQueue::getInstance()->postMessage(m); // inform control about new picture delete info; break; @@ -1382,15 +1382,11 @@ unsigned int OsdOpenVG::handleTask(OpenVGCommand& command) info->handle = handle; info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, reinterpret_cast(handle), NULL); - if (info->reference) return true; - else - { - Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle); - if (handle) vgDestroyImage(handle); - return false; - } - break; + + Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle); + if (handle) vgDestroyImage(handle); + return false; } case OVGreadyEGLImage: { @@ -1538,84 +1534,42 @@ bool OsdOpenVG::processTasks() return worked; } -bool OsdOpenVG::haveOpenVGResponse(unsigned int id, unsigned int* resp) -{ - taskmutex.lock(); - - if (vgresponses.size() > 0) - { - std::deque::iterator itty = vgresponses.begin(); - - while (itty != vgresponses.end()) - { - if ((*itty).id == id) - { - *resp = (*itty).result; - taskmutex.unlock(); - return true; - } - - itty++; - } - } - - taskmutex.unlock(); - return false; -} - unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait) { taskmutex.lock(); if (wait) - { - comm.id = wait_id; - wait_id++; - } + comm.id = wait_id++; else - { comm.id = 0; // we are not waiting - } vgcommands.push_back(comm); taskmutex.unlock(); + threadSignal(); - while (wait) - { - unsigned int resp; + if (!wait) return 0; - if (!haveOpenVGResponse(comm.id, &resp)) + while(1) + { + // Is there a response now? + taskmutex.lock(); + for (auto& vgresponse : vgresponses) { - - // Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand wait_for"); - std::unique_lock ul(vgTaskSignalMutex); - /*auto a = */ vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100)); - ul.unlock(); - /* - if (a == std::cv_status::timeout) - Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand timeout"); - else - Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand no timeout"); - */ - /* - struct timespec target_time; - clock_gettime(CLOCK_REALTIME,&target_time); - target_time.tv_nsec+=1000000LL*100; - if (target_time.tv_nsec>999999999) { - target_time.tv_nsec-=1000000000L; - target_time.tv_sec+=1; + if (vgresponse.id == comm.id) + { + UINT resp = vgresponse.result; + taskmutex.unlock(); + return resp; } - vgtaskSignal.waitForSignalTimed(&target_time); - */ } - else - { - return resp; - } - } + // No. + taskmutex.unlock(); - return 0; + std::unique_lock ul(vgTaskSignalMutex); + vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100)); + ul.unlock(); + } } void OsdOpenVG::destroyImageRef(ImageIndex index) diff --git a/osdopenvg.h b/osdopenvg.h index 194dec1..c66469c 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,6 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE std::deque vgcommands; std::deque vgresponses; bool processTasks(); - bool haveOpenVGResponse(unsigned int id, unsigned int* resp); unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait); unsigned int handleTask(OpenVGCommand& command); //void purgeAllReferences(); @@ -182,6 +182,10 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE ImageOMX* imageomx; #endif + // future + //std::thread renderThread; + //std::mutex threadStartProtect; + }; #endif -- 2.39.5