Skip to content

Commit

Permalink
osdMessageQueue: Undo change to -ve timeout handling
Browse files Browse the repository at this point in the history
The internal mySend() and myReceive() routines do expect a timeout
of -1 to mean wait forever, see the epicsMessageQueueSend() and
epicsMessageQueueReceive() API routines.
  • Loading branch information
anjohnson committed May 4, 2020
1 parent ceb1379 commit 34e0b2f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/libCom/osi/os/default/osdMessageQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ mySend(epicsMessageQueueId pmsg, void *message, unsigned int size,
if ((pmsg->numberOfSendersWaiting > 0)
|| (pmsg->full && (ellFirst(&pmsg->receiveQueue) == NULL))) {
/*
* Return if not allowed to wait
* Return if not allowed to wait. NB -1 means wait forever.
*/
if (timeout <= 0) {
if (timeout == 0) {
epicsMutexUnlock(pmsg->mutex);
return -1;
}

/*
* Wait
* Indicate that we're waiting
*/
struct threadNode threadNode;
threadNode.evp = getEventNode(pmsg);
Expand All @@ -196,19 +196,25 @@ mySend(epicsMessageQueueId pmsg, void *message, unsigned int size,

epicsMutexUnlock(pmsg->mutex);

epicsEventStatus status =
/*
* Wait for receiver to wake us
*/
epicsEventStatus status = timeout < 0 ?
epicsEventWait(threadNode.evp->event) :
epicsEventWaitWithTimeout(threadNode.evp->event, timeout);

epicsMutexMustLock(pmsg->mutex);

if (!threadNode.eventSent) {
/* Receiver didn't take us off the sendQueue, do it ourselves */
ellDelete(&pmsg->sendQueue, &threadNode.link);
pmsg->numberOfSendersWaiting--;
}

freeEventNode(pmsg, threadNode.evp, status);

if (pmsg->full && (ellFirst(&pmsg->receiveQueue) == NULL)) {
/* State of the queue didn't change, exit */
epicsMutexUnlock(pmsg->mutex);
return -1;
}
Expand Down Expand Up @@ -310,9 +316,9 @@ myReceive(epicsMessageQueueId pmsg, void *message, unsigned int size,
}

/*
* Return if not allowed to wait
* Return if not allowed to wait. NB -1 means wait forever.
*/
if (timeout <= 0) {
if (timeout == 0) {
epicsMutexUnlock(pmsg->mutex);
return -1;
}
Expand Down Expand Up @@ -348,7 +354,8 @@ myReceive(epicsMessageQueueId pmsg, void *message, unsigned int size,
/*
* Wait for a message to arrive
*/
epicsEventStatus status =
epicsEventStatus status = timeout < 0 ?
epicsEventWait(threadNode.evp->event) :
epicsEventWaitWithTimeout(threadNode.evp->event, timeout);

epicsMutexMustLock(pmsg->mutex);
Expand Down

0 comments on commit 34e0b2f

Please sign in to comment.