From 14c345b38d57fd814f217eb8465963a08ca79f7e Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期五, 05 二月 2021 17:41:09 +0800
Subject: [PATCH] update

---
 src/shm/hashtable.cpp |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/shm/hashtable.cpp b/src/shm/hashtable.cpp
index 7a5faf4..e435172 100755
--- a/src/shm/hashtable.cpp
+++ b/src/shm/hashtable.cpp
@@ -5,6 +5,9 @@
 #include "logger_factory.h"
 #include <set>
 #include <functional>
+#include <limits.h>
+
+
 
 typedef struct tailq_entry_t
 {
@@ -29,22 +32,12 @@
 
   memset(hashtable, 0, sizeof(hashtable_t));
   hashtable->mutex = svsem_get(IPC_PRIVATE, 1);
-  // hashtable->wlock = svsem_get(IPC_PRIVATE, 1);
-  // hashtable->cond = svsem_get(IPC_PRIVATE, 1);
-  // hashtable->readcnt = 0;
-
-  // FILE * semfile = fopen("./sem.txt", "w+");
-  // if(semfile == NULL) {
-  //   err_exit(errno, "fopen");
-  // }
-  // fprintf(semfile, "hashtable->mutex=%d\n", hashtable->mutex);
-  // fclose(semfile);
+  hashtable->queueCount = 0;
+  hashtable->currentKey = START_KEY;
 }
 
 void hashtable_destroy(hashtable_t *hashtable) {
   svsem_remove( hashtable->mutex);
-  // svsem_remove( hashtable->wlock);
-  // svsem_remove( hashtable->cond);
 }
 
 
@@ -130,6 +123,7 @@
 
         /* mm_free the item as we don't need it anymore. */
         mm_free(item);
+        hashtable->queueCount--;
         svsem_post(hashtable->mutex);
         return oldvalue;
       }
@@ -150,6 +144,7 @@
 
 void hashtable_put(hashtable_t *hashtable, int key, void *value) {
   _hashtable_put(hashtable, key, value); 
+  hashtable->queueCount++;
 }
 
 bool hashtable_check_put(hashtable_t *hashtable, int key, void *value, bool overwrite) {
@@ -183,11 +178,18 @@
   return false;
 }
 
-
+int hashtable_get_queue_count(hashtable_t *hashtable) {
+  return hashtable->queueCount;
+}
 
 int hashtable_alloc_key(hashtable_t *hashtable) {
   int rv;
-  int key = START_KEY;
+  int key = hashtable->currentKey;
+ 
+  if( key == INT_MAX || key < START_KEY) {
+    key = START_KEY;
+  }
+
   rv = svsem_wait(hashtable->mutex);
   if(rv != 0) {
     LoggerFactory::getLogger()->error(errno, "hashtable_alloc_key\n");
@@ -199,10 +201,12 @@
   // 鍗犵敤key
   _hashtable_put(hashtable, key, (void *)1);
 
+  hashtable->currentKey = key;
   rv = svsem_post(hashtable->mutex);
   if(rv != 0) {
     LoggerFactory::getLogger()->error(errno, "hashtable_alloc_key\n");
   }
+
   return key;
 }
 
@@ -279,6 +283,7 @@
     hashtable->array[i] = NULL;
   }
 
+  hashtable->queueCount = 0;
   if((rv = svsem_post(hashtable->mutex)) != 0) {
     LoggerFactory::getLogger()->error(errno, "hashtable_removeall\n");
   }

--
Gitblit v1.8.0