From ef8286da176619bfb9adc09ebdf95ee58783deee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20F=C3=BCrst?= Date: Tue, 30 Jan 2024 15:03:38 +0100 Subject: [PATCH] unset the weak-wait-flag on deallocation for CacheData which is where completion guarantee is required, also extend some comments in CacheData --- offloading-cacher/cache.hpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/offloading-cacher/cache.hpp b/offloading-cacher/cache.hpp index 939a76e..842da8d 100644 --- a/offloading-cacher/cache.hpp +++ b/offloading-cacher/cache.hpp @@ -138,13 +138,26 @@ namespace dsacache { // waits on completion of caching operations // for this task and is safe to be called in - // any state of the object + // any state of the object, if the flag + // FLAG_WAIT_WEAK is set for this instance + // (can also be inherited from the creating + // Cache-Instance or on copy from another + // CacheData-Instance), WaitOnCompletion + // provides no validity guarantees to the + // cache pointer (GetDataLocation() may + // return nullptr even after return + // of the wait function). On error this + // function will set the cache pointer + // to the source to provide validity + // guarantees after returning. void WaitOnCompletion(); // returns the cache data location for this // instance which is valid as long as the - // instance is alive - !!! this may also - // yield a nullptr !!! + // instance is alive + // !!! this may also return a nullptr !!! + // see WaitOnCompletion() for how to achieve + // validity guarantees if required uint8_t* GetDataLocation() const { return cache_->load(); } void SetFlags(const uint64_t flags) { flags_ = flags; } @@ -673,7 +686,11 @@ inline dsacache::CacheData::~CacheData() { if (v == 0) { // on deletion we must ensure that all offloaded // operations have completed successfully + // for this we must unset the possibly active + // flag for weak waiting as we wish completion + // guarantees afterwards + flags_ = UnsetFlag(flags_, FLAG_WAIT_WEAK); WaitOnCompletion(); // only then can we deallocate the memory