From bf4d00d6e3894521196d6fd749a809d6b91e71df Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 27 Feb 2017 13:36:51 +0200 Subject: [PATCH] Add temporary fixes to hashtable These fixes prevent loops turning into eternal loops when optimizations have been turned on. The right remedy is to remove the internal locks from hashtable and use external locks instead. --- server/core/hashtable.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/core/hashtable.c b/server/core/hashtable.c index 3398baffa..1b830eb26 100644 --- a/server/core/hashtable.c +++ b/server/core/hashtable.c @@ -567,10 +567,11 @@ hashtable_read_lock(HASHTABLE *table) while (table->writelock) { spinlock_release(&table->spin); - while (table->writelock) + while (atomic_add(&table->writelock, 1) != 0) { - ; + atomic_add(&table->writelock, -1); } + atomic_add(&table->writelock, -1); spinlock_acquire(&table->spin); } atomic_add(&table->n_readers, 1); @@ -614,10 +615,11 @@ hashtable_write_lock(HASHTABLE *table) spinlock_acquire(&table->spin); do { - while (table->n_readers) + while (atomic_add(&table->n_readers, 1) != 0) { - ; + atomic_add(&table->n_readers, -1); } + atomic_add(&table->n_readers, -1); available = atomic_add(&table->writelock, 1); if (available != 0) {