Files
nitro/packages/react-native-nitro-modules/cpp/utils/BorrowingReference+Owning.hpp
T
Marc RousavyandGitHub c101faf948 feat: Cache toObject(...) using jsi::WeakObject and correctly set externalExternalMemoryPressure (#13)
* feat: Cache `toObject(...)` using `jsi::WeakObject` and set `externalMemoryPressure` properly

* feat: Support caching different JSI types - strongly typed
2024-08-08 12:28:33 +02:00

37 lines
720 B
C++

//
// BorrowingReference+Owning.hpp
// react-native-nitro
//
// Created by Marc Rousavy on 23.06.24.
//
#pragma once
#include "OwningReference.hpp"
namespace margelo::nitro {
template <typename T>
BorrowingReference<T>::BorrowingReference(const OwningReference<T>& ref) {
_value = ref._value;
_isDeleted = ref._isDeleted;
_strongRefCount = ref._strongRefCount;
_weakRefCount = ref._weakRefCount;
_mutex = ref._mutex;
(*_weakRefCount)++;
}
template <typename T>
OwningReference<T> BorrowingReference<T>::lock() const {
std::unique_lock lock(*_mutex);
if (*_isDeleted) {
// return nullptr
return OwningReference<T>();
}
return OwningReference(*this);
}
} // namespace margelo::nitro