diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-07-19 03:53:59 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-07-19 03:58:01 -0700 |
commit | dbf10397ed25001f03ed0eac879e328f625fe0d1 (patch) | |
tree | ec7c6024fe56414657d9441e727743815ac17b25 /tensorflow/core/lib | |
parent | c818bf016d4b48838d943338fd0c8581ab95ada1 (diff) |
A deleter class that calls RefCounted::Unref, and a unique_ptr alias RefCountPtr that uses this deleter.
This class can be used to automate the management of ref-owned objects.
PiperOrigin-RevId: 205217510
Diffstat (limited to 'tensorflow/core/lib')
-rw-r--r-- | tensorflow/core/lib/core/refcount.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tensorflow/core/lib/core/refcount.h b/tensorflow/core/lib/core/refcount.h index eb41f9ff36..87bcfec411 100644 --- a/tensorflow/core/lib/core/refcount.h +++ b/tensorflow/core/lib/core/refcount.h @@ -17,6 +17,8 @@ limitations under the License. #define TENSORFLOW_LIB_CORE_REFCOUNT_H_ #include <atomic> +#include <memory> + #include "tensorflow/core/platform/logging.h" namespace tensorflow { @@ -58,6 +60,15 @@ class RefCounted { void operator=(const RefCounted&) = delete; }; +// A deleter class to form a std::unique_ptr that unrefs objects. +struct RefCountDeleter { + void operator()(tensorflow::core::RefCounted* o) const { o->Unref(); } +}; + +// A unique_ptr that unrefs the owned object on destruction. +template <typename T> +using RefCountPtr = std::unique_ptr<T, RefCountDeleter>; + // Helper class to unref an object when out-of-scope. class ScopedUnref { public: |