From c8604fef7bb4043e36726d7eeaa6afd068012334 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 29 Mar 2007 23:43:54 +0000 Subject: Fix bugs detected by timed mqueue test. git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@178 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/sched/mq_sndinternal.c | 4 ++-- nuttx/sched/mq_timedreceive.c | 10 +++++----- nuttx/sched/mq_timedsend.c | 21 ++++++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'nuttx') diff --git a/nuttx/sched/mq_sndinternal.c b/nuttx/sched/mq_sndinternal.c index 09d56333b..ec5d8a27e 100644 --- a/nuttx/sched/mq_sndinternal.c +++ b/nuttx/sched/mq_sndinternal.c @@ -227,7 +227,7 @@ FAR mqmsg_t *mq_msgalloc(void) * mqdes - Message queue descriptor * * Return Value: - * On success, mq_waitmqnotfull() returns 0 (OK); on error, -1 (ERROR) is + * On success, mq_send() returns 0 (OK); on error, -1 (ERROR) is * returned, with errno set to indicate the error: * * EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the @@ -285,7 +285,7 @@ int mq_waitsend(mqd_t mqdes) rtcb = (FAR _TCB*)g_readytorun.head; rtcb->msgwaitq = msgq; - (msgq->nwaitnotfull)++; + (msgq->nwaitnotempty)++; *get_errno_ptr() = OK; up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL); diff --git a/nuttx/sched/mq_timedreceive.c b/nuttx/sched/mq_timedreceive.c index 39fafdc7d..45aa6a813 100644 --- a/nuttx/sched/mq_timedreceive.c +++ b/nuttx/sched/mq_timedreceive.c @@ -248,22 +248,22 @@ ssize_t mq_timedreceive(mqd_t mqdes, void *msg, size_t msglen, * disabled here so that this time stays valid until the wait begins. */ - ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); + int result = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); /* If the time has already expired and the message queue is empty, * return immediately. */ - if (ret == OK && ticks <= 0) + if (result == OK && ticks <= 0) { - ret = ETIMEDOUT; + result = ETIMEDOUT; } /* Handle any time-related errors */ - if (ret != OK) + if (result != OK) { - *get_errno_ptr() = ret; + *get_errno_ptr() = result; irqrestore(saved_state); sched_unlock(); wd_delete(wdog); diff --git a/nuttx/sched/mq_timedsend.c b/nuttx/sched/mq_timedsend.c index a35edb9f8..05b7ea5d2 100644 --- a/nuttx/sched/mq_timedsend.c +++ b/nuttx/sched/mq_timedsend.c @@ -240,7 +240,6 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, else { sint32 ticks; - int result; /* We are not in an interupt handler and the message queue is full. * set up a timed wait for the message queue to become non-full. @@ -249,7 +248,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, * disabled here so that this time stays valid until the wait begins. */ - result = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); + int result = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); /* If the time has already expired and the message queue is empty, * return immediately. @@ -262,6 +261,14 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, /* Handle any time-related errors */ + if (result != OK) + { + *get_errno_ptr() = result; + ret = ERROR; + } + + /* Start the watchdog and begin the wait for MQ not full */ + if (result == OK) { /* Start the watchdog */ @@ -270,7 +277,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, /* And wait for the message queue to be non-empty */ - result = mq_waitsend(mqdes); + ret = mq_waitsend(mqdes); /* This may return with an error and errno set to either EINTR * or ETIMEOUT. Cancel the watchdog timer in any event. @@ -288,11 +295,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, * the message structure. */ - if (result != OK) - { - *get_errno_ptr() = result; - } - else + if (ret == OK) { mqmsg = mq_msgalloc(); } @@ -305,7 +308,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, if (mqmsg) { - /* Yes, peforrm the message send. */ + /* Yes, peform the message send. */ ret = mq_dosend(mqdes, mqmsg, msg, msglen, prio); } -- cgit v1.2.3