aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.h
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-01-03 13:18:12 +0100
committerPer Larsson <[email protected]>2022-01-03 13:18:12 +0100
commit44dcfa3326d5fa143299f90171c3cd51b440b741 (patch)
tree510405a86e23291db53ba0f9dc57477a350a16f1 /zenserver/cache/structuredcachestore.h
parentRun tests via xmake instead of executing target. (diff)
downloadzen-44dcfa3326d5fa143299f90171c3cd51b440b741.tar.xz
zen-44dcfa3326d5fa143299f90171c3cd51b440b741.zip
Changed timestamp to atomic int64.
Diffstat (limited to 'zenserver/cache/structuredcachestore.h')
-rw-r--r--zenserver/cache/structuredcachestore.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h
index b39aa405e..8b015d0fb 100644
--- a/zenserver/cache/structuredcachestore.h
+++ b/zenserver/cache/structuredcachestore.h
@@ -159,12 +159,25 @@ private:
{
struct BucketValue
{
- GcClock::Tick LastAccess{};
- IoBuffer Payload;
+ IoBuffer Payload;
+ std::atomic_int64_t LastAccess;
+
+ BucketValue() : Payload(), LastAccess() {}
+ BucketValue(IoBuffer Value, const int64_t Timestamp) : Payload(Value), LastAccess(Timestamp) {}
+ BucketValue(const BucketValue& V) : Payload(V.Payload), LastAccess(V.LastAccess.load(std::memory_order_relaxed)) {}
+ BucketValue(BucketValue&& V) : Payload(std::move(V.Payload)), LastAccess(V.LastAccess.load(std::memory_order_relaxed)) {}
+
+ BucketValue& operator=(const BucketValue& V) { return *this = BucketValue(V); }
+ BucketValue& operator=(BucketValue&& V)
+ {
+ Payload = std::move(V.Payload);
+ LastAccess.store(V.LastAccess.load(), std::memory_order_relaxed);
+ return *this;
+ }
};
- RwLock m_bucketLock;
- tsl::robin_map<IoHash, BucketValue> m_cacheMap;
+ RwLock m_BucketLock;
+ tsl::robin_map<IoHash, BucketValue> m_CacheMap;
std::atomic_uint64_t m_TotalSize{};
bool Get(const IoHash& HashKey, ZenCacheValue& OutValue);
@@ -238,8 +251,21 @@ private:
struct IndexEntry
{
- DiskLocation Location;
- GcClock::Tick LastAccess{};
+ DiskLocation Location;
+ std::atomic_int64_t LastAccess;
+
+ IndexEntry() : Location(), LastAccess() {}
+ IndexEntry(const DiskLocation& Loc, const int64_t Timestamp) : Location(Loc), LastAccess(Timestamp) {}
+ IndexEntry(const IndexEntry& E) : Location(E.Location), LastAccess(E.LastAccess.load(std::memory_order_relaxed)) {}
+ IndexEntry(IndexEntry&& E) : Location(std::move(E.Location)), LastAccess(E.LastAccess.load(std::memory_order_relaxed)) {}
+
+ IndexEntry& operator=(const IndexEntry& E) { return *this = IndexEntry(E); }
+ IndexEntry& operator=(IndexEntry&& E)
+ {
+ Location = std::move(E.Location);
+ LastAccess.store(E.LastAccess.load(), std::memory_order_relaxed);
+ return *this;
+ }
};
using IndexMap = tsl::robin_map<IoHash, IndexEntry, IoHash::Hasher>;
@@ -252,7 +278,10 @@ private:
void BuildPath(PathBuilderBase& Path, const IoHash& HashKey);
void PutStandaloneCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
bool GetStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey, ZenCacheValue& OutValue);
- void DeleteStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey, const std::filesystem::path& Path, std::error_code& Ec);
+ void DeleteStandaloneCacheValue(const DiskLocation& Loc,
+ const IoHash& HashKey,
+ const std::filesystem::path& Path,
+ std::error_code& Ec);
bool GetInlineCacheValue(const DiskLocation& Loc, ZenCacheValue& OutValue);
void OpenLog(const std::filesystem::path& BucketDir, const bool IsNew);