wangzhengquan
2020-07-07 379f42982b8c57ee6511cb8e498019f454323977
squeue/include/queue_factory.h
@@ -7,17 +7,26 @@
#include "SLinkedLockFreeQueue.h"
namespace QueueFactory{
   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;
   }
   template <typename T>
   SLinkedLockFreeQueue<T>* createLinkedLockFreeQueue(int key, size_t size) {
      hashtable_t *hashtable;
      SLinkedLockFreeQueue<T> *queue;
      int first;
      first = mm_init(sizeof(hashtable_t), (void **)&hashtable);
      if (first)
         hashtable_init(hashtable);
      hashtable_t *hashtable = getHashTable();
      
      if ((queue = (SLinkedLockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
         queue = new SLinkedLockFreeQueue<T>(size);
@@ -30,14 +39,9 @@
   template <typename T>
   LockFreeQueue<T>* createArrayLockFreeQueue(int key, size_t size=16) {
      hashtable_t *hashtable;
      LockFreeQueue<T> *queue;
      int first;
      first = mm_init(sizeof(hashtable_t), (void **)&hashtable);
      if (first)
         hashtable_init(hashtable);;
      hashtable_t *hashtable = getHashTable();
      //LockFreeQueue<int, 10000> q;
      if ((queue = (LockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
         queue = new LockFreeQueue<T>(size);
@@ -49,9 +53,21 @@
   template <typename T>
   LockFreeQueue<T>* createQueue(int key, size_t size) {
   LockFreeQueue<T>* createQueue(int key, size_t size = 16) {
      return QueueFactory::createArrayLockFreeQueue<T>(key, size);
   }
   /**
    * destroy queue
   */
   template <typename T>
   void dropQueue(int key) {
      LockFreeQueue<T> *queue = QueueFactory::createQueue<T> (key);
      delete queue;
      hashtable_t *hashtable = getHashTable();
      hashtable_remove(hashtable, key);
   }
}
#endif