wangzhengquan
2020-07-06 b5f793b46a8baf51bfd8ac678de1895a9479817e
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
#ifndef QFACTORY_H
#define QFACTORY_H  
#include "usg_common.h"
#include "mm.h"
#include "hashtable.h"
#include "SArrayLockFreeQueue.h"
#include "SLinkedLockFreeQueue.h"
 
namespace QFactory{
 
    
     
 
    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);
        
        if ((queue = (SLinkedLockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
            queue = new SLinkedLockFreeQueue<T>(size);
            hashtable_put(hashtable,  key, (void *)queue);
        }
 
        return queue;
    }
 
 
    template <typename T>
    SArrayLockFreeQueue<T>* createArrayLockFreeQueue(int key, size_t size) {
        hashtable_t *hashtable;
        SArrayLockFreeQueue<T> *queue;
        int first;
          
        first = mm_init(sizeof(hashtable_t), (void **)&hashtable);
          
        if (first)
           hashtable_init(hashtable);;
        
        if ((queue = (SArrayLockFreeQueue<T> *)hashtable_get(hashtable, key)) == NULL ) {
            queue = new SArrayLockFreeQueue <T>(size);
            hashtable_put(hashtable,  key, (void *)queue);
        }
 
        return queue;
    }
 
 
    template <typename T>
    SAbstractQueue<T>* createQueue(int key, size_t size) {
        return QFactory::createLinkedLockFreeQueue<T>(key, size);
    }
 
}
#endif