[C++ API] Added reference counting to ObjectRef (#13058)

* Added reference counting to ObjectRef

* Addressed the comments
This commit is contained in:
Alind Khare
2020-12-24 12:32:52 -05:00
committed by GitHub
parent 4bcd475671
commit 2059a2090d
2 changed files with 32 additions and 26 deletions
+12
View File
@@ -16,6 +16,7 @@ template <typename T>
class ObjectRef {
public:
ObjectRef();
~ObjectRef();
ObjectRef(const ObjectID &id);
@@ -46,6 +47,17 @@ ObjectRef<T>::ObjectRef() {}
template <typename T>
ObjectRef<T>::ObjectRef(const ObjectID &id) {
id_ = id;
if (CoreWorkerProcess::IsInitialized()) {
auto &core_worker = CoreWorkerProcess::GetCoreWorker();
core_worker.AddLocalReference(id_);
}
}
template <typename T>
ObjectRef<T>::~ObjectRef() {
if (CoreWorkerProcess::IsInitialized()) {
auto &core_worker = CoreWorkerProcess::GetCoreWorker();
core_worker.RemoveLocalReference(id_);
}
}
template <typename T>