From 027ad5058185510c2b2df715614babbdcdd68aab Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 17 May 2022 03:34:37 +0000 Subject: [PATCH] Dictionary use correct acquire/release semantics --- src/db.cpp | 5 +++-- src/dict.cpp | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 5b67a4198..0ad3df99f 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -3263,10 +3263,11 @@ bool redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command dictEntry **table; __atomic_load(&c->db->m_pdict->ht[iht].table, &table, __ATOMIC_RELAXED); if (table != nullptr) { - dictEntry *de = table[hT]; + dictEntry *de; + __atomic_load(&table[hT], &de, __ATOMIC_ACQUIRE); while (de != nullptr) { _mm_prefetch(dictGetKey(de), _MM_HINT_T2); - de = de->next; + __atomic_load(&de->next, &de, __ATOMIC_ACQUIRE); } } if (!dictIsRehashing(c->db->m_pdict)) diff --git a/src/dict.cpp b/src/dict.cpp index e8de025f7..b29c0e24b 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -403,7 +403,7 @@ int dictRehash(dict *d, int n) { dictAsyncRehashCtl::dictAsyncRehashCtl(struct dict *d, dictAsyncRehashCtl *next) : dict(d), next(next) { queue.reserve(c_targetQueueSize); - __atomic_fetch_add(&d->refcount, 1, __ATOMIC_RELEASE); + __atomic_fetch_add(&d->refcount, 1, __ATOMIC_ACQ_REL); this->rehashIdxBase = d->rehashidx; } @@ -810,6 +810,8 @@ int _dictClear(dict *d, dictht *ht, void(callback)(void *)) { if (callback && (i & 65535) == 0) callback(d->privdata); if ((he = ht->table[i]) == NULL) continue; + dictEntry *deNull = nullptr; + __atomic_store(&ht->table[i], &deNull, __ATOMIC_RELEASE); while(he) { nextHe = he->next; if (d->asyncdata && (ssize_t)i < d->rehashidx) {