From f85c9b875b060681b51f57b15074ba1c7c9f5636 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 20 七月 2020 11:10:02 +0800 Subject: [PATCH] update --- test2/test_queue_wrapper.c | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-) diff --git a/test2/test_queue_wrapper.c b/test2/test_queue_wrapper.c index efcc881..6483fb3 100644 --- a/test2/test_queue_wrapper.c +++ b/test2/test_queue_wrapper.c @@ -1,49 +1,54 @@ #include "shm_queue_wrapper.h" #include "mm.h" -typedef struct message_t -{ - char method[20]; - int code; +// typedef struct message_t +// { +// char method[20]; +// int code; -} message_t; +// } message_t; void test1() { unsigned int i = 0; - int key = 2; + int key = 1; size_t qsize = 16; - void * queue = shmqueue_init( key, qsize, sizeof(message_t)); - message_t item; + void * queue = shmqueue_create( &key, qsize); + //message_t item; + char msg[100]; + void *rtmsg; + int size; for(i = 0; i < qsize; i++) { - sprintf(item.method, "hello"); - item.code = i ; + sprintf(msg, "%d hello", i); //鍏ラ槦 - if(shmqueue_push(queue, (void *)&item)) { - printf("push:%d %s\n", item.code, item.method ); + if(shmqueue_push(queue, (void *)msg, sizeof(msg))) { + printf("push: %s\n", msg ); } } - - struct timespec timeout = {1, 0}; - + printf("key == %d\n", key); + // struct timespec timeout = {1, 0}; + // int keys[] = {1,2}; + // shm_remove_queues_exclue((void *)keys, 1); i = 0; // 鍑洪槦 - while((shmqueue_pop_timeout(queue, (void *)&item, &timeout)) ) { - printf("pop:%d %s\n", item.code, item.method ); + while((shmqueue_pop_timeout(queue, &rtmsg, &size, 1, 0)) ) { + printf("pop: %s\n", (char *)rtmsg ); + free(rtmsg); // cout << item.pic << endl; i++; } //閿�姣侀槦鍒� - shmqueue_destroy(queue); + shmqueue_drop(queue); } int main () { + shm_init(512); test1(); //鏁翠釜杩涚▼閫�鍑烘椂闇�瑕佹墽琛岃繖涓柟娉曪紝璇ユ柟娉曢鍏堜細妫�鏌ユ槸鍚﹁繕鏈夊叾浠栬繘绋嬪湪浣跨敤璇ュ叡浜唴瀛橈紝濡傛灉杩樻湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ氨鍙槸detach,濡傛灉娌℃湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ垯閿�姣佹暣鍧楀唴瀛樸�� - mm_destroy(); + shm_destroy(); return 0; } \ No newline at end of file -- Gitblit v1.8.0