From: Amos Jeffries Date: Tue, 2 Jun 2015 11:05:22 +0000 (-0700) Subject: Convert StoreMap to std::atomic X-Git-Tag: merge-candidate-3-v1~72^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d2b13bab2a04fc59095c6a57d36811906955ac7c;p=thirdparty%2Fsquid.git Convert StoreMap to std::atomic Implemented copy-constructor and assignment operator for StoreMapSlice since the default ones used by AtomicWord were not thread safe and C++11 explicitly deletes them for std::atomic. --- diff --git a/src/fs/rock/RockRebuild.cc b/src/fs/rock/RockRebuild.cc index a5b6844094..60ee1c420b 100644 --- a/src/fs/rock/RockRebuild.cc +++ b/src/fs/rock/RockRebuild.cc @@ -281,7 +281,7 @@ Rock::Rebuild::importEntry(Ipc::StoreMapAnchor &anchor, const sfileno fileno, co cache_key key[SQUID_MD5_DIGEST_LENGTH]; StoreEntry loadedE; const uint64_t knownSize = header.entrySize > 0 ? - header.entrySize : anchor.basics.swap_file_sz.get(); + header.entrySize : anchor.basics.swap_file_sz.load(); if (!storeRebuildParseEntry(buf, loadedE, key, counts, knownSize)) return false; diff --git a/src/ipc/StoreMap.h b/src/ipc/StoreMap.h index b523e065ba..a3ec8b1736 100644 --- a/src/ipc/StoreMap.h +++ b/src/ipc/StoreMap.h @@ -9,7 +9,6 @@ #ifndef SQUID_IPC_STORE_MAP_H #define SQUID_IPC_STORE_MAP_H -#include "ipc/AtomicWord.h" #include "ipc/mem/FlexibleArray.h" #include "ipc/mem/Pointer.h" #include "ipc/ReadWriteLock.h" @@ -29,9 +28,19 @@ public: typedef uint32_t Size; StoreMapSlice(): size(0), next(-1) {} - - Atomic::WordT size; ///< slice contents size - Atomic::WordT next; ///< ID of the next entry slice + StoreMapSlice(const StoreMapSlice &o) { + size.exchange(o.size); + next.exchange(o.next); + } + + StoreMapSlice &operator =(const StoreMapSlice &o) { + size.store(o.size); + next.store(o.next); + return *this; + } + + std::atomic size; ///< slice contents size + std::atomic next; ///< ID of the next entry slice }; /// Maintains shareable information about a StoreEntry as a whole. @@ -61,7 +70,7 @@ public: public: mutable ReadWriteLock lock; ///< protects slot data below - Atomic::WordT waitingToBeFreed; ///< may be accessed w/o a lock + std::atomic waitingToBeFreed; ///< may be accessed w/o a lock // fields marked with [app] can be modified when appending-while-reading @@ -73,13 +82,13 @@ public: time_t lastref; time_t expires; time_t lastmod; - Atomic::WordT swap_file_sz; // [app] + std::atomic swap_file_sz; // [app] uint16_t refcount; uint16_t flags; } basics; /// where the chain of StoreEntry slices begins [app] - Atomic::WordT start; + std::atomic start; }; /// an array of shareable Items @@ -115,8 +124,8 @@ public: size_t sharedMemorySize() const; static size_t SharedMemorySize(const int anAnchorLimit); - Atomic::Word count; ///< current number of entries - Atomic::WordT victim; ///< starting point for purge search + std::atomic count; ///< current number of entries + std::atomic victim; ///< starting point for purge search const int capacity; ///< total number of anchors Ipc::Mem::FlexibleArray items; ///< anchors storage };