From aeaeda81cfe398081a7c1a5c287981c8df974aa2 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 27 七月 2020 19:03:38 +0800 Subject: [PATCH] commit --- src/queue/hashtable.c | 34 ++++++++++++++++++++++------------ 1 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/queue/hashtable.c b/src/queue/hashtable.c index 43c59ce..1fa6266 100755 --- a/src/queue/hashtable.c +++ b/src/queue/hashtable.c @@ -91,9 +91,12 @@ size_t code = hashcode(key); tailq_entry_t *item; void *oldvalue; + + SemUtil::dec(hashtable->wlock); tailq_header_t *my_tailq_head = hashtable->array[code] ; if ( my_tailq_head == NULL) { + SemUtil::inc(hashtable->wlock); return NULL; } else @@ -108,11 +111,12 @@ /* mm_free the item as we don't need it anymore. */ mm_free(item); - + SemUtil::inc(hashtable->wlock); return oldvalue; } } } + SemUtil::inc(hashtable->wlock); return NULL; } @@ -124,6 +128,7 @@ void hashtable_removeall(hashtable_t *hashtable) { tailq_entry_t *item; + SemUtil::dec(hashtable->wlock); for (int i = 0; i < MAPSIZE; i++) { tailq_header_t *my_tailq_head = hashtable->array[i] ; @@ -139,6 +144,7 @@ mm_free(my_tailq_head); hashtable->array[i] = NULL; } + SemUtil::inc(hashtable->wlock); } /** @@ -171,18 +177,7 @@ } -int hashtable_alloc_key(hashtable_t *hashtable) { - int key = START_KEY; - SemUtil::dec(hashtable->wlock); - while(_hashtable_get(hashtable, key) != NULL) { - key++; - } - - _hashtable_put(hashtable, key, (void *)1); - SemUtil::inc(hashtable->wlock); - return key; -} void *hashtable_get(hashtable_t *hashtable, int key) { SemUtil::dec(hashtable->mutex); @@ -245,6 +240,19 @@ } } +int hashtable_alloc_key(hashtable_t *hashtable) { + int key = START_KEY; + SemUtil::dec(hashtable->wlock); + + while(_hashtable_get(hashtable, key) != NULL) { + key++; + } + + _hashtable_put(hashtable, key, (void *)1); + SemUtil::inc(hashtable->wlock); + return key; +} + std::set<int> * hashtable_keyset(hashtable_t *hashtable) { std::set<int> *keyset = new std::set<int>; tailq_entry_t *item; @@ -261,3 +269,5 @@ } return keyset; } + + -- Gitblit v1.8.0