#ifndef QFACTORY_H #define QFACTORY_H #include "usg_common.h" #include "mm.h" #include "hashtable.h" #include "lock_free_queue.h" #include "SLinkedLockFreeQueue.h" namespace QueueFactory{ template SLinkedLockFreeQueue* createLinkedLockFreeQueue(int key, size_t size) { hashtable_t *hashtable; SLinkedLockFreeQueue *queue; int first; first = mm_init(sizeof(hashtable_t), (void **)&hashtable); if (first) hashtable_init(hashtable); if ((queue = (SLinkedLockFreeQueue *)hashtable_get(hashtable, key)) == NULL ) { queue = new SLinkedLockFreeQueue(size); hashtable_put(hashtable, key, (void *)queue); } return queue; } template LockFreeQueue* createArrayLockFreeQueue(int key, size_t size=16) { hashtable_t *hashtable; LockFreeQueue *queue; int first; first = mm_init(sizeof(hashtable_t), (void **)&hashtable); if (first) hashtable_init(hashtable);; //LockFreeQueue q; if ((queue = (LockFreeQueue *)hashtable_get(hashtable, key)) == NULL ) { queue = new LockFreeQueue(size); hashtable_put(hashtable, key, (void *)queue); } return queue; } template LockFreeQueue* createQueue(int key, size_t size) { return QueueFactory::createArrayLockFreeQueue(key, size); } } #endif