diff options
Diffstat (limited to 'tensorflow/core/lib/core/refcount.h')
-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: |