[+] ADestructionWatcher::ADestructionWatcher(ADestructionWatcher &&move);

[+] ADestructionWatcher::ADestructionWatcher(const ADestructionWatcher &copy);
[+] ADestructionWatcher::ADestructionWatcher &operator =(ADestructionWatcher &&move);
[+] ADestructionWatcher::ADestructionWatcher &operator =(const ADestructionWatcher &copy);
This commit is contained in:
Reece Wilson 2024-03-17 19:00:05 +00:00
parent 1e53972a2a
commit c3cb380eca

View File

@ -42,6 +42,12 @@ namespace Aurora::Utility
inline bool IsObservedAlive();
inline bool IsObservedDead();
inline ADestructionWatcher(ADestructionWatcher &&move);
inline ADestructionWatcher(const ADestructionWatcher &copy);
inline ADestructionWatcher &operator =(ADestructionWatcher &&move);
inline ADestructionWatcher &operator =(const ADestructionWatcher &copy);
protected:
// Note that since the parent object is in the midst of destruction; you should not be manually calling the destroy operations of it or its' children.
// C++ construction and the inverse destruction order are well defined.
@ -198,6 +204,52 @@ namespace Aurora::Utility
this->OnSelfDTOR();
}
ADestructionWatcher::ADestructionWatcher(ADestructionWatcher &&move)
{
AU_LOCK_GUARD(move.selfLock);
if (auto pParent = AuExchange(move.pParent, nullptr))
{
pParent->RemoveWatcher(&move);
this->Observe(pParent);
}
}
ADestructionWatcher::ADestructionWatcher(const ADestructionWatcher &copy)
{
AU_LOCK_GUARD(copy.selfLock);
if (auto &pParent = copy.pParent)
{
this->Observe(pParent);
}
}
ADestructionWatcher &ADestructionWatcher::operator =(ADestructionWatcher &&move)
{
AU_LOCK_GUARD(move.selfLock);
if (auto pParent = AuExchange(move.pParent, nullptr))
{
pParent->RemoveWatcher(&move);
this->Observe(pParent);
}
return *this;
}
ADestructionWatcher &ADestructionWatcher::operator =(const ADestructionWatcher &copy)
{
AU_LOCK_GUARD(copy.selfLock);
if (auto &pParent = copy.pParent)
{
this->Observe(pParent);
}
return *this;
}
void ADestructionWatcher::Observe(DestructionWatch *pWatch)
{
AU_LOCK_GUARD(pWatch->mutex);