]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Convert StoreMap to std::atomic
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 2 Jun 2015 11:05:22 +0000 (04:05 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 2 Jun 2015 11:05:22 +0000 (04:05 -0700)
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.

src/fs/rock/RockRebuild.cc
src/ipc/StoreMap.h

index a5b68440944850cc164c201c0f0807fd55ed1508..60ee1c420b511bfd03582546b64a0aecf48ad1c1 100644 (file)
@@ -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;
 
index b523e065ba2c8f52d5692cbc82b24a9487c29349..a3ec8b1736c68bb7a5bb527d72ecbdd266f04e35 100644 (file)
@@ -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> size; ///< slice contents size
-    Atomic::WordT<StoreMapSliceId> 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> size; ///< slice contents size
+    std::atomic<StoreMapSliceId> 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<uint8_t> waitingToBeFreed; ///< may be accessed w/o a lock
+    std::atomic<uint8_t> 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<uint64_t> swap_file_sz; // [app]
+        std::atomic<uint64_t> swap_file_sz; // [app]
         uint16_t refcount;
         uint16_t flags;
     } basics;
 
     /// where the chain of StoreEntry slices begins [app]
-    Atomic::WordT<StoreMapSliceId> start;
+    std::atomic<StoreMapSliceId> 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<uint32_t> victim; ///< starting point for purge search
+    std::atomic<int32_t> count; ///< current number of entries
+    std::atomic<uint32_t> victim; ///< starting point for purge search
     const int capacity; ///< total number of anchors
     Ipc::Mem::FlexibleArray<StoreMapAnchor> items; ///< anchors storage
 };