From b06f6f82097405883142cbe44294fcc040f2aa3c Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Thu, 4 Jun 2015 18:29:04 +0300 Subject: [PATCH] foreign_ptr: introduce make_local_and_release() Sometimes remote data has to be copied to local cpu, but if data is already local copy can be avoided. Introduce helper function that moves or copies data depending on origin cpu. --- core/distributed.hh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/distributed.hh b/core/distributed.hh index 4f33d04f72..60844a6f6e 100644 --- a/core/distributed.hh +++ b/core/distributed.hh @@ -357,6 +357,17 @@ public: }); } } + /// release the wrapped object on a local cpu. If executed on cpu + /// other than the one object was created on object will be copied + /// to local memory. + typename std::pointer_traits::element_type make_local_and_release() { + if (on_origin()) { + return std::move(*_value); + } else { + // copied to caller's cpu here + return *_value; + } + } /// Accesses the wrapped object. element_type& operator*() const { return *_value; } /// Accesses the wrapped object.