| | |
| | | #include "test.h" |
| | | |
| | | using namespace std; |
| | | |
| | | int main () { |
| | | void testStruct() { |
| | | unsigned int i = 0; |
| | | |
| | | int key = 2; |
| | |
| | | struct Item item; |
| | | |
| | | size_t qsize = 16; |
| | | LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | |
| | | //LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | SHMQueue<struct Item> *queue = new SHMQueue<struct Item>(key, 16); |
| | | // LockFreeQueue<struct Item> queue(16); |
| | | for(i = 0; i < qsize; i++) { |
| | | |
| | |
| | | |
| | | |
| | | |
| | | struct timespec timeout = {5, 0}; |
| | | struct timespec timeout = {1, 0}; |
| | | |
| | | i = 0; |
| | | while((queue->pop(item)) ) { |
| | | while((queue->pop_timeout(item, &timeout)) ) { |
| | | cout << i << " pop:" << item.pic << ", " << item.info << endl; |
| | | // cout << item.pic << endl; |
| | | i++; |
| | | } |
| | | |
| | | |
| | | destroy(key); |
| | | delete queue; |
| | | } |
| | | |
| | | void testString() { |
| | | unsigned int i = 0; |
| | | std::ostringstream outstr; |
| | | int key = 2; |
| | | |
| | | shmstring item; |
| | | |
| | | size_t qsize = 16; |
| | | //LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | SHMQueue<shmstring> *queue = new SHMQueue<shmstring>(key, 16); |
| | | // LockFreeQueue<struct Item> queue(16); |
| | | for(i = 0; i < qsize; i++) { |
| | | outstr.seekp(0); |
| | | outstr << "hello " << i ; |
| | | if(queue->push(outstr.str().c_str())) { |
| | | cout << i << " push:" << outstr.str() << endl; |
| | | } |
| | | } |
| | | |
| | | // for(i = 0; i < qsize; i++) { |
| | | |
| | | // //queue.dequeue(item); |
| | | |
| | | // item = (*queue)[i]; |
| | | // cout << "i=" << i << ":" << item << endl; |
| | | // } |
| | | |
| | | |
| | | |
| | | struct timespec timeout = {1, 0}; |
| | | |
| | | i = 0; |
| | | while((queue->pop_timeout(item, &timeout)) ) { |
| | | cout << i << " pop:" << item << endl; |
| | | // cout << item.pic << endl; |
| | | i++; |
| | | } |
| | | |
| | | delete queue; |
| | | } |
| | | |
| | | |
| | | // void testArr(unsigned size) { |
| | | // unsigned int i = 0; |
| | | // int key = 2; |
| | | |
| | | // char item[size]; |
| | | |
| | | // size_t qsize = 16; |
| | | // //LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | // SHMQueue<char[size]> *queue = new SHMQueue<char[size]>(key, 16); |
| | | // // LockFreeQueue<struct Item> queue(16); |
| | | // for(i = 0; i < qsize; i++) { |
| | | // sprintf(item, "%d hello", i); |
| | | // if(queue->push(item)) { |
| | | // cout << i << " push:" << item << endl; |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // struct timespec timeout = {1, 0}; |
| | | |
| | | // i = 0; |
| | | // while((queue->pop_timeout(item, &timeout)) ) { |
| | | // cout << i << " pop:" << item << endl; |
| | | // // cout << item.pic << endl; |
| | | // i++; |
| | | // } |
| | | |
| | | // delete queue; |
| | | // } |
| | | |
| | | |
| | | int main () { |
| | | mm_init(512); |
| | | // testArr(12); |
| | | testStruct(); |
| | | |
| | | mm_destroy(); |
| | | return 0; |
| | | } |