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