From ef87c1da16a3d87a4363ea3f090a64b1c1bbcbb9 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 09 七月 2020 10:12:57 +0800
Subject: [PATCH] add lib

---
 squeue/include/queue_factory.h |  110 ++++++++++++++++++++++++++++++------------------------
 1 files changed, 61 insertions(+), 49 deletions(-)

diff --git a/squeue/include/queue_factory.h b/squeue/include/queue_factory.h
index 23446b0..67537c6 100644
--- a/squeue/include/queue_factory.h
+++ b/squeue/include/queue_factory.h
@@ -1,59 +1,71 @@
-#ifndef QFACTORY_H
-#define QFACTORY_H  
-#include "usg_common.h"
-#include "mm.h"
-#include "hashtable.h"
-#include "lock_free_queue.h"
+// #ifndef QFACTORY_H
+// #define QFACTORY_H  
+// #include "usg_common.h"
+// #include "mm.h"
+// #include "hashtable.h"
+// #include "lock_free_queue.h"
 
-class QueueFactory{
-private:
+// class QueueFactory{
+	 
+// private:
 
-	static hashtable_t * getHashTable() {
-		static hashtable_t *hashtable = NULL;
-		int first;
+// 	static hashtable_t * getHashTable() {
+// 		static hashtable_t *hashtable = NULL;
+// 		int first;
 		  
-		if(hashtable == NULL) {
-			first = mm_init(sizeof(hashtable_t), (void **)&hashtable);
-			if (first)
-			   hashtable_init(hashtable);
-		}
-		return hashtable;
+// 		if(hashtable == NULL) {
+// 			first = mm_init(sizeof(hashtable_t), (void **)&hashtable);
+// 			if (first)
+// 			   hashtable_init(hashtable);
+// 		}
+// 		return hashtable;
 		
-	}
+// 	}
+
+
+// 	template <typename T> static
+// 	LockFreeQueue<T>* _createQueue(int key, size_t size = 16) {
+// 		LockFreeQueue<T> *queue;
+// 		hashtable_t *hashtable = getHashTable();
+// 		//LockFreeQueue<int, 10000> q;
+// 		if ((queue = (LockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
+// 			queue = new LockFreeQueue<T>(size);
+// 			hashtable_put(hashtable,  key, (void *)queue);
+// 		}
+
+		
+// 		return queue;
+// 	}
 
 	 
+// public:
 
-	template <typename T> static
-	LockFreeQueue<T>* createArrayLockFreeQueue(int key, size_t size=16) {
-		 
-		LockFreeQueue<T> *queue;
-		hashtable_t *hashtable = getHashTable();
-		//LockFreeQueue<int, 10000> q;
-		if ((queue = (LockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
-			queue = new LockFreeQueue<T>(size);
-			hashtable_put(hashtable,  key, (void *)queue);
-		}
+// 	template <typename T> static
+// 	LockFreeQueue<T>* createQueue(int key, size_t size = 16) {
+// 		LockFreeQueue<T> *queue = _createQueue<T>(key, size);
+// 		queue->reference++; 
+// 		LoggerFactory::getLogger().debug("createQueue reference===%d", queue->reference.load());
+// 		return queue;
+// 	}
 
-		return queue;
-	}
+// 	/**
+// 	 * destroy queue
+// 	*/
+// 	template <typename T> static
+// 	void dropQueue(int key) {
+// 		LockFreeQueue<T> *queue = _createQueue<T> (key);
+// 		if(queue == NULL)
+// 			return;
 
-public:
+// 		queue->reference--;
+// 		LoggerFactory::getLogger().debug("dropQueue reference===%d", queue->reference.load());
+// 		if(queue->reference == 0) {
+// 			delete queue;
+// 			hashtable_t *hashtable = getHashTable();
+// 			hashtable_remove(hashtable, key);
+// 		}
+		
+// 	}
 
-	template <typename T> static
-	LockFreeQueue<T>* createQueue(int key, size_t size = 16) {
-		return QueueFactory::createArrayLockFreeQueue<T>(key, size);
-	}
-
-	/**
-	 * destroy queue
-	*/
-	template <typename T> static
-	void dropQueue(int key) {
-		LockFreeQueue<T> *queue = QueueFactory::createQueue<T> (key);
-		delete queue;
-		hashtable_t *hashtable = getHashTable();
-		hashtable_remove(hashtable, key);
-	}
-
-};
-#endif
+// };
+// #endif

--
Gitblit v1.8.0