From c8a89134a78a7ffd721dc1909c7fc9bb0517c85f Mon Sep 17 00:00:00 2001 From: Andrey Golubev Date: Wed, 16 Jan 2019 18:15:44 +0300 Subject: [PATCH] GAPI: fix GCall misuse in unrollExpr --- modules/gapi/src/api/gcall.cpp | 7 ++++++- modules/gapi/src/compiler/gmodelbuilder.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/gapi/src/api/gcall.cpp b/modules/gapi/src/api/gcall.cpp index 2dd823daa6..c6acd15101 100644 --- a/modules/gapi/src/api/gcall.cpp +++ b/modules/gapi/src/api/gcall.cpp @@ -28,9 +28,14 @@ cv::GCall::GCall(const cv::GKernel &k) cv::GCall::~GCall() { + // FIXME: current behavior of the destructor can cause troubles in a threaded environment. GCall + // is not supposed to be accessed for modification within multiple threads. There should be a + // way to ensure somehow that no problem occurs in future. For now, this is a reminder that + // GCall is not supposed to be copied inside a code block that is executed in parallel. + // When a GCall object is destroyed (and GCall::Priv is likely still alive, // as there might be other references), reset m_node to break cycle. - m_priv->m_node = GNode(); + m_priv->m_node = GNode(); } void cv::GCall::setArgs(std::vector &&args) diff --git a/modules/gapi/src/compiler/gmodelbuilder.cpp b/modules/gapi/src/compiler/gmodelbuilder.cpp index c9b2fbbdfd..7eb2ecf2c0 100644 --- a/modules/gapi/src/compiler/gmodelbuilder.cpp +++ b/modules/gapi/src/compiler/gmodelbuilder.cpp @@ -128,7 +128,7 @@ cv::gimpl::Unrolled cv::gimpl::unrollExpr(const GProtoArgs &ins, // then add its operands to stack to continue recursion. ops.visit(&node.priv(), node); - const cv::GCall call = origin.node.call(); + const cv::GCall& call = origin.node.call(); const cv::GCall::Priv& call_p = call.priv(); // Put the outputs object description of the node