From: Alex Rousskov Date: Fri, 4 Feb 2011 04:26:18 +0000 (-0700) Subject: When we are done writing, we still need to keep the reading lock X-Git-Tag: take02~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72c2d42db61e8ac97093ab6045aa53a208db9ff3;p=thirdparty%2Fsquid.git When we are done writing, we still need to keep the reading lock because the StoreEntry is not gone yet and may refer back to the Slot. --- diff --git a/src/fs/rock/RockDirMap.cc b/src/fs/rock/RockDirMap.cc index c03e86fc32..63ef20cfa8 100644 --- a/src/fs/rock/RockDirMap.cc +++ b/src/fs/rock/RockDirMap.cc @@ -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) { diff --git a/src/fs/rock/RockDirMap.h b/src/fs/rock/RockDirMap.h index 16addbeb10..e85ee3df89 100644 --- a/src/fs/rock/RockDirMap.h +++ b/src/fs/rock/RockDirMap.h @@ -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