From dbe91d2d130d03ff832e7fd8fb13a283d9eb36eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Tue, 1 Jan 2013 21:13:29 +0100 Subject: [PATCH] Rename uc_thread_queue_get to uc_thread_queue_tryget, introduce uc_thread_queue_get macro --- include/ucore/ucore_threadqueue.h | 12 ++++++++++-- src/ucore_threadqueue.c | 2 +- test/test_threadqueue.c | 12 ++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/ucore/ucore_threadqueue.h b/include/ucore/ucore_threadqueue.h index a6cfe4c..8bc3c17 100644 --- a/include/ucore/ucore_threadqueue.h +++ b/include/ucore/ucore_threadqueue.h @@ -175,7 +175,7 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg); /** * Gets a message from a queue * - * thread_queue_get gets a message from the specified queue, it will block + * thread_queue_tryget gets a message from the specified queue, it will block * the caling thread untill a message arrives, or the (optional) timeout occurs. * If timeout is NULL, there will be no timeout, and thread_queue_get will wait * untill a message arrives. @@ -194,7 +194,15 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg); * * @return 0 on success EINVAL if queue is NULL ETIMEDOUT if timeout occurs */ -int uc_thread_queue_get(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg **msg); +int uc_thread_queue_tryget(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg **msg); + +/** + * Like uc_thread_queue_tryget, but will wait indefintly for an item + * to become available + * @see uc_thread_queue_tryget + */ +#define uc_thread_queue_get(queue, msg)\ +uc_thread_queue_tryget(queue, NULL, msg) /** diff --git a/src/ucore_threadqueue.c b/src/ucore_threadqueue.c index 0f23afd..9866cfc 100644 --- a/src/ucore_threadqueue.c +++ b/src/ucore_threadqueue.c @@ -104,7 +104,7 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg) } -int uc_thread_queue_get(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg **msg) +int uc_thread_queue_tryget(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg **msg) { int rc = 0; struct timespec abstimeout; diff --git a/test/test_threadqueue.c b/test/test_threadqueue.c index 3c7c11f..f57d579 100644 --- a/test/test_threadqueue.c +++ b/test/test_threadqueue.c @@ -45,7 +45,7 @@ START_TEST (test_thread_queue_one_thread) for (i = 0; i < 51; i++) { struct uc_threadmsg *msg; struct thr_msg *my_msg; - fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0); + fail_if(uc_thread_queue_get(&queue, &msg) != 0); my_msg = (struct thr_msg *)msg; fail_if(my_msg->a != i); free(my_msg); @@ -94,7 +94,7 @@ static void *test_thread_queue_reader_writer_func(void *arg) for (i = 0; i < READER_WRITER_NUM_MSG; i++) { struct uc_threadmsg *msg; struct thr_msg *my_msg; - fail_if(uc_thread_queue_get(queue, NULL, &msg) != 0); + fail_if(uc_thread_queue_get(queue, &msg) != 0); my_msg = (struct thr_msg *)msg; fail_if(my_msg->a != i); free(my_msg); @@ -188,7 +188,7 @@ START_TEST (test_thread_queue_multiple_writers) for (i = 0; i < READER_WRITER_NUM_MSG * 3; i++) { struct uc_threadmsg *msg; struct thr_msg *my_msg; - fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0); + fail_if(uc_thread_queue_get(&queue, &msg) != 0); my_msg = (struct thr_msg *)msg; if (my_msg->a == READER_WRITER_NUM_MSG - 1) @@ -213,7 +213,7 @@ START_TEST (test_thread_queue_timeout1) fail_if(uc_thread_queue_init(&queue, 100) != 0); - fail_if(uc_thread_queue_get(&queue, &timeout, &msg) != ETIMEDOUT); + fail_if(uc_thread_queue_tryget(&queue, &timeout, &msg) != ETIMEDOUT); uc_thread_queue_destroy(&queue, NULL); END_TEST @@ -225,8 +225,8 @@ void *thread_test_thread_queue_timeout2(void *arg) struct thr_msg *my_msg; struct timespec timeout = {0, 2000}; - fail_if(uc_thread_queue_get(queue, &timeout, &msg) != 0); - fail_if(uc_thread_queue_get(queue, &timeout, &msg) != ETIMEDOUT); + fail_if(uc_thread_queue_tryget(queue, &timeout, &msg) != 0); + fail_if(uc_thread_queue_tryget(queue, &timeout, &msg) != ETIMEDOUT); my_msg = (struct thr_msg *)msg; fail_if(my_msg->b != 12345);