]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
When we are done writing, we still need to keep the reading lock
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Feb 2011 04:26:18 +0000 (21:26 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Feb 2011 04:26:18 +0000 (21:26 -0700)
because the StoreEntry is not gone yet and may refer back to the Slot.

src/fs/rock/RockDirMap.cc
src/fs/rock/RockDirMap.h

index c03e86fc323629cd88016803aefe5db64390ebb3..63ef20cfa8946c9e0a18891d159c19ec604e17d4 100644 (file)
@@ -65,7 +65,7 @@ Rock::DirMap::closeForWriting(const sfileno fileno)
     assert(valid(fileno));
     Slot &s = shared->slots[fileno];
     assert(s.state.swap_if(Slot::Writeable, Slot::Readable));
-    s.releaseExclusiveLock();
+    s.switchExclusiveToSharedLock();
 }
 
 bool
@@ -306,6 +306,12 @@ Rock::Slot::releaseExclusiveLock()
     assert(writers-- > 0);
 }
 
+void
+Rock::Slot::switchExclusiveToSharedLock() const
+{
+    ++readers; // must be done before we release exclusive control
+    releaseExclusiveLock();
+}
 
 Rock::DirMap::Shared::Shared(const int aLimit): limit(aLimit), count(0)
 {
index 16addbeb1061b9c4404adcd6e55b8a671e73deaf..e85ee3df89136606c53e9f97d3a27f91a215da93 100644 (file)
@@ -38,6 +38,7 @@ public:
     bool exclusiveLock(); ///< lock for modification or return false
     void releaseSharedLock() const; ///< undo successful sharedLock()
     void releaseExclusiveLock(); ///< undo successful exclusiveLock()
+    void switchExclusiveToSharedLock(); ///< trade exclusive for shared access
 
 public:
     // we want two uint64_t, but older GCCs lack __sync_fetch_and_add_8