Changed shared_ptr to unique_ptr for Priv storage in fluid::View

This commit is contained in:
Ruslan Garnov 2019-11-13 15:46:52 +03:00
parent 6c93e42d94
commit 65ccafd494
6 changed files with 29 additions and 18 deletions

View File

@ -85,10 +85,13 @@ public:
Priv& priv(); // internal use only Priv& priv(); // internal use only
const Priv& priv() const; // internal use only const Priv& priv() const; // internal use only
View(Priv* p); View(std::unique_ptr<Priv>&& p);
View(View&& v);
View& operator=(View&& v);
~View();
private: private:
std::shared_ptr<Priv> m_priv; std::unique_ptr<Priv> m_priv;
const Cache* m_cache; const Cache* m_cache;
}; };
@ -139,6 +142,7 @@ public:
inline const GMatDesc& meta() const { return m_cache->m_desc; } inline const GMatDesc& meta() const { return m_cache->m_desc; }
View mkView(int borderSize, bool ownStorage); View mkView(int borderSize, bool ownStorage);
void addView(const View* v);
class GAPI_EXPORTS Priv; // internal use only class GAPI_EXPORTS Priv; // internal use only
Priv& priv(); // internal use only Priv& priv(); // internal use only

View File

@ -172,7 +172,7 @@ template<> struct fluid_get_in<cv::GMat>
{ {
static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx) static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx)
{ {
return in_args[idx].unsafe_get<cv::gapi::fluid::View>(); return *in_args[idx].unsafe_get<cv::gapi::fluid::View*>();
} }
}; };

View File

@ -880,10 +880,10 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
auto inEdge = GModel::getInEdgeByPort(m_g, agent->op_handle, in_idx); auto inEdge = GModel::getInEdgeByPort(m_g, agent->op_handle, in_idx);
auto ownStorage = fg.metadata(inEdge).get<FluidUseOwnBorderBuffer>().use; auto ownStorage = fg.metadata(inEdge).get<FluidUseOwnBorderBuffer>().use;
gapi::fluid::View view = buffer.mkView(fu.border_size, ownStorage);
// NB: It is safe to keep ptr as view lifetime is buffer lifetime // NB: It is safe to keep ptr as view lifetime is buffer lifetime
agent->in_views[in_idx] = view; agent->in_views[in_idx] = buffer.mkView(fu.border_size, ownStorage);
agent->in_args[in_idx] = GArg(view); agent->in_args[in_idx] = GArg(&agent->in_views[in_idx]);
buffer.addView(&agent->in_views[in_idx]);
} }
else else
{ {

View File

@ -577,7 +577,7 @@ bool fluid::Buffer::Priv::full() const
{ {
// reset with maximum possible value and then find minimum // reset with maximum possible value and then find minimum
slowest_y = m_desc.size.height; slowest_y = m_desc.size.height;
for (const auto &v : m_views) slowest_y = std::min(slowest_y, v.y()); for (const auto &v : m_views) slowest_y = std::min(slowest_y, v->y());
} }
return m_write_caret + lpi() - slowest_y > m_storage->rows(); return m_write_caret + lpi() - slowest_y > m_storage->rows();
@ -609,7 +609,7 @@ void fluid::Buffer::Priv::reset()
int fluid::Buffer::Priv::size() const int fluid::Buffer::Priv::size() const
{ {
std::size_t view_sz = 0; std::size_t view_sz = 0;
for (const auto &v : m_views) view_sz += v.priv().size(); for (const auto &v : m_views) view_sz += v->priv().size();
auto total = view_sz; auto total = view_sz;
if (m_storage) total += m_storage->size(); if (m_storage) total += m_storage->size();
@ -693,17 +693,24 @@ int fluid::Buffer::lpi() const
return m_priv->lpi(); return m_priv->lpi();
} }
fluid::View::View(Priv* p) fluid::View::View(std::unique_ptr<Priv>&& p)
: m_priv(p), m_cache(&p->cache()) : m_priv(std::move(p)), m_cache(&m_priv->cache())
{ /* nothing */ } { /* nothing */ }
fluid::View::View(View&&) = default;
fluid::View& fluid::View::operator=(View&&) = default;
fluid::View::~View() = default;
fluid::View fluid::Buffer::mkView(int borderSize, bool ownStorage) fluid::View fluid::Buffer::mkView(int borderSize, bool ownStorage)
{ {
// FIXME: logic outside of Priv (because View takes pointer to Buffer) // FIXME: logic outside of Priv (because View takes pointer to Buffer)
auto view = ownStorage ? View(new ViewPrivWithOwnBorder(this, borderSize)) return ownStorage ? View(std::unique_ptr<ViewPrivWithOwnBorder>(new ViewPrivWithOwnBorder(this, borderSize)))
: View(new ViewPrivWithoutOwnBorder(this, borderSize)); : View(std::unique_ptr<ViewPrivWithoutOwnBorder>(new ViewPrivWithoutOwnBorder(this, borderSize)));
m_priv->addView(view); }
return view;
void fluid::Buffer::addView(const View* v)
{
m_priv->addView(v);
} }
void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os) void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
@ -717,7 +724,7 @@ void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
<<" (phys " << "[" << p.storage().cols() << " x " << p.storage().rows() << "]" << ") :" <<" (phys " << "[" << p.storage().cols() << " x " << p.storage().rows() << "]" << ") :"
<< " w: " << p.m_write_caret << " w: " << p.m_write_caret
<< ", r: ["; << ", r: [";
for (const auto &v : p.m_views) { os << &v.priv() << ":" << v.y() << " "; } for (const auto &v : p.m_views) { os << &v->priv() << ":" << v->y() << " "; }
os << "], avail: " << buffer.linesReady() os << "], avail: " << buffer.linesReady()
<< std::endl; << std::endl;
} }

View File

@ -239,7 +239,7 @@ class GAPI_EXPORTS Buffer::Priv
int m_write_caret = -1; int m_write_caret = -1;
std::vector<View> m_views; std::vector<const View*> m_views;
std::unique_ptr<BufferStorage> m_storage; std::unique_ptr<BufferStorage> m_storage;
@ -265,7 +265,7 @@ public:
void allocate(BorderOpt border, int border_size, int line_consumption, int skew); void allocate(BorderOpt border, int border_size, int line_consumption, int skew);
void bindTo(const cv::gapi::own::Mat &data, bool is_input); void bindTo(const cv::gapi::own::Mat &data, bool is_input);
inline void addView(const View& view) { m_views.push_back(view); } inline void addView(const View* view) { m_views.emplace_back(view); }
inline const GMatDesc& meta() const { return m_desc; } inline const GMatDesc& meta() const { return m_desc; }

View File

@ -101,7 +101,7 @@ namespace
GAPI_FLUID_KERNEL(GClone, I::GClone, false) GAPI_FLUID_KERNEL(GClone, I::GClone, false)
{ {
static const int Window = 1; static const int Window = 1;
static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer) static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer&)
{ {
HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE); HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE);
} }