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
This commit is contained in:
patacongo 2007-03-29 23:43:54 +00:00
parent 448c7f4618
commit b1127822ed
3 changed files with 19 additions and 16 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);
}