mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 02:00:12 +08:00
[C++ API] Added reference counting to ObjectRef (#13058)
* Added reference counting to ObjectRef * Addressed the comments
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user