From b90ba316b54db321d3e8aaac7df93b46d80b9d9c Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 22 十二月 2020 15:47:41 +0800
Subject: [PATCH] 三个没有回收的信号

---
 src/queue/hashtable.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/queue/hashtable.c b/src/queue/hashtable.c
index ed3fe34..243067b 100755
--- a/src/queue/hashtable.c
+++ b/src/queue/hashtable.c
@@ -23,6 +23,8 @@
 
 static size_t hashcode(int key);
 
+static struct timespec TIMEOUT = {1, 0};
+
 void hashtable_init(hashtable_t *hashtable )
 {
   
@@ -32,6 +34,12 @@
   hashtable->cond = SemUtil::get(IPC_PRIVATE, 1);
   hashtable->readcnt = 0;
 
+}
+
+void hashtable_destroy(hashtable_t *hashtable) {
+  SemUtil::remove( hashtable->mutex);
+  SemUtil::remove( hashtable->wlock);
+  SemUtil::remove( hashtable->cond);
 }
 
 
@@ -179,12 +187,9 @@
   /*printf("hashfun = %ld\n", code);*/
 }
 
-
-
-
 void *hashtable_get(hashtable_t *hashtable, int key) {
-   struct timespec timeout = {1, 0};
-   if (SemUtil::dec_timeout(hashtable->mutex, &timeout) != 0) {
+  
+   if (SemUtil::dec_timeout(hashtable->mutex, &TIMEOUT) != 0) {
     SemUtil::inc(hashtable->mutex);
     SemUtil::dec(hashtable->mutex);
    }
@@ -317,8 +322,7 @@
 int hashtable_alloc_key(hashtable_t *hashtable) {
   int key = START_KEY;
 
-  struct timespec timeout = {1, 0};
-  if (SemUtil::dec_timeout(hashtable->wlock, &timeout) != 0) {
+  if (SemUtil::dec_timeout(hashtable->wlock, &TIMEOUT) != 0) {
     SemUtil::inc(hashtable->wlock);
     SemUtil::dec(hashtable->wlock);
   }

--
Gitblit v1.8.0