Skip to content

Commit

Permalink
Fix unity build with SUPPORT_CLOCK_CACHE (#9309)
Browse files Browse the repository at this point in the history
Summary:
After #9126

Pull Request resolved: #9309

Test Plan: CI

Reviewed By: ajkr

Differential Revision: D33188902

Pulled By: pdillinger

fbshipit-source-id: 54bf34e33c2b30b1b8dc2a0229e84c194321b606
  • Loading branch information
pdillinger authored and facebook-github-bot committed Dec 17, 2021
1 parent 6b5e28a commit 0d9b256
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cache/clock_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,22 @@ struct CacheHandle {
};

// Key of hash map. We store hash value with the key for convenience.
struct CacheKey {
struct ClockCacheKey {
Slice key;
uint32_t hash_value;

CacheKey() = default;
ClockCacheKey() = default;

CacheKey(const Slice& k, uint32_t h) {
ClockCacheKey(const Slice& k, uint32_t h) {
key = k;
hash_value = h;
}

static bool equal(const CacheKey& a, const CacheKey& b) {
static bool equal(const ClockCacheKey& a, const ClockCacheKey& b) {
return a.hash_value == b.hash_value && a.key == b.key;
}

static size_t hash(const CacheKey& a) {
static size_t hash(const ClockCacheKey& a) {
return static_cast<size_t>(a.hash_value);
}
};
Expand All @@ -260,7 +260,8 @@ struct CleanupContext {
class ClockCacheShard final : public CacheShard {
public:
// Hash map type.
using HashTable = tbb::concurrent_hash_map<CacheKey, CacheHandle*, CacheKey>;
using HashTable =
tbb::concurrent_hash_map<ClockCacheKey, CacheHandle*, ClockCacheKey>;

ClockCacheShard();
~ClockCacheShard() override;
Expand Down Expand Up @@ -559,7 +560,7 @@ bool ClockCacheShard::TryEvict(CacheHandle* handle, CleanupContext* context) {
if (handle->flags.compare_exchange_strong(flags, 0, std::memory_order_acquire,
std::memory_order_relaxed)) {
bool erased __attribute__((__unused__)) =
table_.erase(CacheKey(handle->key, handle->hash));
table_.erase(ClockCacheKey(handle->key, handle->hash));
assert(erased);
RecycleHandle(handle, context);
return true;
Expand Down Expand Up @@ -656,13 +657,13 @@ CacheHandle* ClockCacheShard::Insert(
// relative updates (fetch_add, etc).
handle->flags.store(flags, std::memory_order_relaxed);
HashTable::accessor accessor;
if (table_.find(accessor, CacheKey(key, hash))) {
if (table_.find(accessor, ClockCacheKey(key, hash))) {
*overwritten = true;
CacheHandle* existing_handle = accessor->second;
table_.erase(accessor);
UnsetInCache(existing_handle, context);
}
table_.insert(HashTable::value_type(CacheKey(key, hash), handle));
table_.insert(HashTable::value_type(ClockCacheKey(key, hash), handle));
if (hold_reference) {
pinned_usage_.fetch_add(total_charge, std::memory_order_relaxed);
}
Expand Down Expand Up @@ -701,7 +702,7 @@ Status ClockCacheShard::Insert(const Slice& key, uint32_t hash, void* value,

Cache::Handle* ClockCacheShard::Lookup(const Slice& key, uint32_t hash) {
HashTable::const_accessor accessor;
if (!table_.find(accessor, CacheKey(key, hash))) {
if (!table_.find(accessor, ClockCacheKey(key, hash))) {
return nullptr;
}
CacheHandle* handle = accessor->second;
Expand Down Expand Up @@ -746,7 +747,7 @@ bool ClockCacheShard::EraseAndConfirm(const Slice& key, uint32_t hash,
MutexLock l(&mutex_);
HashTable::accessor accessor;
bool erased = false;
if (table_.find(accessor, CacheKey(key, hash))) {
if (table_.find(accessor, ClockCacheKey(key, hash))) {
CacheHandle* handle = accessor->second;
table_.erase(accessor);
erased = UnsetInCache(handle, context);
Expand Down

0 comments on commit 0d9b256

Please sign in to comment.