summaryrefslogtreecommitdiff
path: root/assoc.c
diff options
context:
space:
mode:
authorDaniel Schemmel <daniel.schemmel@comsys.rwth-aachen.de>2019-11-09 23:26:34 +0100
committerdormando <dormando@rydia.net>2019-11-09 19:11:06 -0800
commit4575e1f9668a467aa4dc628101509f7f5a5a2efe (patch)
tree100ca28b92c27efeaa1fee57d8d83661898911c7 /assoc.c
parent8a8346f815a6aeb7bfb90bd5fe2432e8b4616924 (diff)
downloadmemcached-4575e1f9668a467aa4dc628101509f7f5a5a2efe.tar.gz
Fix data race in `assoc_start_expand`
Diffstat (limited to 'assoc.c')
-rw-r--r--assoc.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/assoc.c b/assoc.c
index b67fc01..68235d5 100644
--- a/assoc.c
+++ b/assoc.c
@@ -48,7 +48,6 @@ static item** old_hashtable = 0;
/* Flag: Are we in the middle of expanding now? */
static bool expanding = false;
-static bool started_expanding = false;
/*
* During expansion we migrate values with bucket granularity; this is how
@@ -141,13 +140,11 @@ static void assoc_expand(void) {
}
void assoc_start_expand(uint64_t curr_items) {
- if (started_expanding)
- return;
-
- if (curr_items > (hashsize(hashpower) * 3) / 2 &&
- hashpower < HASHPOWER_MAX) {
- started_expanding = true;
- pthread_cond_signal(&maintenance_cond);
+ if (pthread_mutex_trylock(&maintenance_lock) == 0) {
+ if (curr_items > (hashsize(hashpower) * 3) / 2 && hashpower < HASHPOWER_MAX) {
+ pthread_cond_signal(&maintenance_cond);
+ }
+ pthread_mutex_unlock(&maintenance_lock);
}
}
@@ -246,7 +243,6 @@ static void *assoc_maintenance_thread(void *arg) {
if (!expanding) {
/* We are done expanding.. just wait for next invocation */
- started_expanding = false;
pthread_cond_wait(&maintenance_cond, &maintenance_lock);
/* assoc_expand() swaps out the hash table entirely, so we need
* all threads to not hold any references related to the hash