Rename uc_thread_queue_get to uc_thread_queue_tryget, introduce
uc_thread_queue_get macro
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user