Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / src / api / gcall.cpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #include "precomp.hpp"
9 #include <cassert>
10 #include "opencv2/gapi/gcall.hpp"
11 #include "api/gcall_priv.hpp"
12
13 // GCall private implementation ////////////////////////////////////////////////
14 cv::GCall::Priv::Priv(const cv::GKernel &k)
15     : m_k(k)
16 {
17 }
18
19 // GCall public implementation /////////////////////////////////////////////////
20
21 cv::GCall::GCall(const cv::GKernel &k)
22     : m_priv(new Priv(k))
23 {
24     // Here we have a reference to GNode,
25     // and GNode has a reference to us. Cycle! Now see destructor.
26     m_priv->m_node = GNode::Call(*this);
27 }
28
29 cv::GCall::~GCall()
30 {
31     // FIXME: current behavior of the destructor can cause troubles in a threaded environment. GCall
32     // is not supposed to be accessed for modification within multiple threads. There should be a
33     // way to ensure somehow that no problem occurs in future. For now, this is a reminder that
34     // GCall is not supposed to be copied inside a code block that is executed in parallel.
35
36     // When a GCall object is destroyed (and GCall::Priv is likely still alive,
37     // as there might be other references), reset m_node to break cycle.
38     m_priv->m_node = GNode();
39 }
40
41 void cv::GCall::setArgs(std::vector<GArg> &&args)
42 {
43     // FIXME: Check if argument number is matching kernel prototype
44     m_priv->m_args = std::move(args);
45 }
46
47 cv::GMat cv::GCall::yield(int output)
48 {
49     return cv::GMat(m_priv->m_node, output);
50 }
51
52 cv::GScalar cv::GCall::yieldScalar(int output)
53 {
54     return cv::GScalar(m_priv->m_node, output);
55 }
56
57 cv::detail::GArrayU cv::GCall::yieldArray(int output)
58 {
59     return cv::detail::GArrayU(m_priv->m_node, output);
60 }
61
62 cv::GCall::Priv& cv::GCall::priv()
63 {
64     return *m_priv;
65 }
66
67 const cv::GCall::Priv& cv::GCall::priv() const
68 {
69     return *m_priv;
70 }