From 9f0009faeaa0960f57fcacea91b45997258016e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 1 Sep 2015 14:32:27 +0000 Subject: synch more with git svn path=/trunk/externals/iem/iemnet/; revision=17546 --- build/autotests/tests/threadedqueue.c | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 build/autotests/tests/threadedqueue.c (limited to 'build/autotests/tests/threadedqueue.c') diff --git a/build/autotests/tests/threadedqueue.c b/build/autotests/tests/threadedqueue.c new file mode 100644 index 0000000..b68f11d --- /dev/null +++ b/build/autotests/tests/threadedqueue.c @@ -0,0 +1,77 @@ +#include + +#include + +#define NUMCHUNKS 1000 + + +typedef union { + unsigned char cp; + int count; +} data_t; +static int producer(t_iemnet_queue*q, unsigned int count, unsigned int msec) { + unsigned int i; + data_t data; + for(i=0; isize) { + error("size mismatch %d!=%d", sizeof(data_t), chunk->size); + fail(); + } + data=chunk->data; + //printf("%d ", data->count); + iemnet__chunk_destroy(chunk); + } + printf("\n"); + return 0; +} +static void* consumer_thread(void*qq) { + t_iemnet_queue*q=(t_iemnet_queue*)qq; + consumer(q); + return NULL; +} + +void threadedqueue_setup(void) { + pthread_t thread; + pthread_attr_t threadattr; + + t_iemnet_queue*q=queue_create(); + + /* prepare child thread */ + if(pthread_attr_init(&threadattr) < 0) { + error("warning: could not prepare child thread"); + fail(); + } + if(pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED) < 0) { + error("warning: could not prepare child thread..."); + fail(); + } + + if(pthread_create(&thread, &threadattr, consumer_thread, q) < 0) { + error("warning: could not create child thread"); + fail(); + } + + + producer(q, 1000, 1); + + + queue_destroy(q); + pass(); +} -- cgit v1.2.1