From 0dbd9ba1b52d7d82caddc4d6e585ee408b71190c Mon Sep 17 00:00:00 2001 From: Junru Shao Date: Tue, 9 Mar 2021 05:37:18 -0800 Subject: [PATCH] [Runtime][Object] Add Object::unique() (#7615) --- include/tvm/runtime/object.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index b5cf77d590f6..70ab7688c450 100644 --- a/include/tvm/runtime/object.h +++ b/include/tvm/runtime/object.h @@ -185,7 +185,11 @@ class TVM_DLL Object { */ template inline bool IsInstance() const; - + /*! + * \return Weather the cell has only one reference + * \note We use stl style naming to be consistent with known API in shared_ptr. + */ + inline bool unique() const; /*! * \brief Get the type key of the corresponding index from runtime. * \param tindex The type index. @@ -831,6 +835,8 @@ inline bool Object::IsInstance() const { } } +inline bool Object::unique() const { return use_count() == 1; } + template inline const ObjectType* ObjectRef::as() const { if (data_ != nullptr && data_->IsInstance()) {