wangzhengquan
2020-07-09 91f003aac4c95f4d2a2fc0782c9bea9d484b6919
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// #ifndef QFACTORY_H
// #define QFACTORY_H  
// #include "usg_common.h"
// #include "mm.h"
// #include "hashtable.h"
// #include "lock_free_queue.h"
 
// class QueueFactory{
     
// private:
 
//     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;
        
//     }
 
 
//     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>* 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;
//     }
 
//     /**
//      * destroy queue
//     */
//     template <typename T> static
//     void dropQueue(int key) {
//         LockFreeQueue<T> *queue = _createQueue<T> (key);
//         if(queue == NULL)
//             return;
 
//         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);
//         }
        
//     }
 
// };
// #endif