86 ~SharedAsset() { CESIUM_ASSERT(this->_referenceCount == 0); }
92 SharedAsset(
const SharedAsset& rhs)
93 : ExtensibleObject(rhs), _referenceCount(0), _pDepot(nullptr) {}
99 SharedAsset(SharedAsset&& rhs) noexcept
100 : ExtensibleObject(std::move(rhs)),
108 SharedAsset& operator=(
const SharedAsset& rhs)
noexcept {
110 CesiumUtility::ExtensibleObject::operator=(rhs);
119 SharedAsset& operator=(SharedAsset&& rhs)
noexcept {
121 CesiumUtility::ExtensibleObject::operator=(std::move(rhs));
127 void addReference(
bool threadOwnsDepotLock)
const noexcept {
128 const int32_t prevReferences = this->_referenceCount++;
129 if (this->_pDepot && prevReferences <= 0) {
130 this->_pDepot->unmarkDeletionCandidate(
131 *
static_cast<const T*
>(
this),
132 threadOwnsDepotLock);
136 void releaseReference(
bool threadOwnsDepotLock)
const noexcept {
137 CESIUM_ASSERT(this->_referenceCount > 0);
138 const int32_t references = --this->_referenceCount;
139 if (references == 0) {
140 IDepotOwningAsset<T>* pDepot = this->_pDepot;
143 pDepot->markDeletionCandidate(
144 *
static_cast<const T*
>(
this),
145 threadOwnsDepotLock);
148 delete static_cast<const T*
>(
this);
153 mutable std::atomic<std::int32_t> _referenceCount{0};
154 IDepotOwningAsset<T>* _pDepot{
nullptr};
155 bool _isInvalidated{
false};
158 template <
typename TAssetType,
typename TAssetKey,
typename TContext>
159 friend class CesiumAsync::SharedAssetDepot;