From c3cb380eca22abfaf8f62fee73e459c85aab8115 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sun, 17 Mar 2024 19:00:05 +0000 Subject: [PATCH] [+] ADestructionWatcher::ADestructionWatcher(ADestructionWatcher &&move); [+] ADestructionWatcher::ADestructionWatcher(const ADestructionWatcher ©); [+] ADestructionWatcher::ADestructionWatcher &operator =(ADestructionWatcher &&move); [+] ADestructionWatcher::ADestructionWatcher &operator =(const ADestructionWatcher ©); --- Include/Aurora/Utility/DestructionWatch.hpp | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Include/Aurora/Utility/DestructionWatch.hpp b/Include/Aurora/Utility/DestructionWatch.hpp index ca3189fb..466f1fb0 100644 --- a/Include/Aurora/Utility/DestructionWatch.hpp +++ b/Include/Aurora/Utility/DestructionWatch.hpp @@ -42,6 +42,12 @@ namespace Aurora::Utility inline bool IsObservedAlive(); inline bool IsObservedDead(); + inline ADestructionWatcher(ADestructionWatcher &&move); + inline ADestructionWatcher(const ADestructionWatcher ©); + + inline ADestructionWatcher &operator =(ADestructionWatcher &&move); + inline ADestructionWatcher &operator =(const ADestructionWatcher ©); + 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 ©) + { + 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 ©) + { + 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);