Mercurial > hg > orthanc
changeset 3566:ee508761d753
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 08 Nov 2019 17:34:54 +0100 |
parents | 2999a6e9456b (current diff) 4812825e69fc (diff) |
children | 8b8edb26d4c1 |
files | |
diffstat | 3 files changed, 39 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Cache/MemoryObjectCache.cpp Thu Nov 07 17:02:19 2019 +0100 +++ b/Core/Cache/MemoryObjectCache.cpp Fri Nov 08 17:34:54 2019 +0100 @@ -208,31 +208,52 @@ } - MemoryObjectCache::Reader::Reader(MemoryObjectCache& cache, - const std::string& key) : -#if !defined(__EMSCRIPTEN__) - contentLock_(cache.contentMutex_), - cacheLock_(cache.cacheMutex_), -#endif + MemoryObjectCache::Accessor::Accessor(MemoryObjectCache& cache, + const std::string& key, + bool unique) : item_(NULL) { +#if !defined(__EMSCRIPTEN__) + if (unique) + { + writerLock_ = WriterLock(cache.contentMutex_); + } + else + { + readerLock_ = ReaderLock(cache.contentMutex_); + } + + // Lock the global structure of the cache, must be *after* the + // reader/writer lock + cacheLock_ = boost::mutex::scoped_lock(cache.cacheMutex_); +#endif + if (cache.content_.Contains(key, item_)) { cache.content_.MakeMostRecent(key); } - + #if !defined(__EMSCRIPTEN__) cacheLock_.unlock(); if (item_ == NULL) { - contentLock_.unlock(); + // This item does not exist in the cache, we can release the + // reader/writer lock + if (unique) + { + writerLock_.unlock(); + } + else + { + readerLock_.unlock(); + } } #endif } - ICacheable& MemoryObjectCache::Reader::GetValue() const + ICacheable& MemoryObjectCache::Accessor::GetValue() const { if (IsValid()) { @@ -245,7 +266,7 @@ } - const boost::posix_time::ptime& MemoryObjectCache::Reader::GetTime() const + const boost::posix_time::ptime& MemoryObjectCache::Accessor::GetTime() const { if (IsValid()) {
--- a/Core/Cache/MemoryObjectCache.h Thu Nov 07 17:02:19 2019 +0100 +++ b/Core/Cache/MemoryObjectCache.h Fri Nov 08 17:34:54 2019 +0100 @@ -83,19 +83,21 @@ void Invalidate(const std::string& key); - class Reader : public boost::noncopyable + class Accessor : public boost::noncopyable { private: #if !defined(__EMSCRIPTEN__) - ReaderLock contentLock_; + ReaderLock readerLock_; + WriterLock writerLock_; boost::mutex::scoped_lock cacheLock_; #endif - Item* item_; + Item* item_; public: - Reader(MemoryObjectCache& cache, - const std::string& key); + Accessor(MemoryObjectCache& cache, + const std::string& key, + bool unique); bool IsValid() const {
--- a/Core/Cache/MemoryStringCache.cpp Thu Nov 07 17:02:19 2019 +0100 +++ b/Core/Cache/MemoryStringCache.cpp Fri Nov 08 17:34:54 2019 +0100 @@ -69,7 +69,7 @@ bool MemoryStringCache::Fetch(std::string& value, const std::string& key) { - MemoryObjectCache::Reader reader(cache_, key); + MemoryObjectCache::Accessor reader(cache_, key, false /* multiple readers are allowed */); if (reader.IsValid()) {