Skip to content

Commit

Permalink
Fix #1279, Refactored rtems queue logic to mimic posix logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Price committed Aug 31, 2022
1 parent 94e5858 commit a3ddd01
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/os/rtems/src/os-impl-queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size,
rtems_interval ticks;
int tick_count;
rtems_option option_set;
size_t rtems_size;
/* Implementation read size */
size_t impl_size;
rtems_id rtems_queue_id;
OS_impl_queue_internal_record_t *impl;

Expand Down Expand Up @@ -198,40 +199,40 @@ int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size,
*/
status = rtems_message_queue_receive(rtems_queue_id, /* message queue descriptor */
data, /* pointer to message buffer */
&rtems_size, /* returned size of message */
&impl_size, /* returned size of message */
option_set, /* wait option */
ticks /* timeout */
);

if (status == RTEMS_SUCCESSFUL)
{
return_code = OS_SUCCESS;
}
else if (status == RTEMS_TIMEOUT)
{
return_code = OS_QUEUE_TIMEOUT;
}
else if (status == RTEMS_UNSATISFIED)
{
return_code = OS_QUEUE_EMPTY;
}
else
{
/* Something else went wrong */
return_code = OS_ERROR;
OS_DEBUG("Unhandled queue_receive error: %s\n", rtems_status_text(status));
}

/*
** If a valid message was obtained fill in queue size, otherwise fill in zero on error
*/
if (status == RTEMS_SUCCESSFUL)
{
*size_copied = rtems_size;
}
else
if (status != RTEMS_SUCCESSFUL)
{
*size_copied = 0;

/* Map the rtems error to the most appropriate OSAL return code */
if( (timeout == OS_PEND) && (status != RTEMS_TIMEOUT)){
/* OS_PEND was supposed to pend forever until a message arrived
* so something else is wrong. Otherwise, at this point the only
* "acceptable" errno is TIMEDOUT for the other cases.
*/
return_code = OS_ERROR;
}
else if (status == RTEMS_UNSATISFIED)
{
return_code = OS_QUEUE_EMPTY;
}
else if (status == RTEMS_TIMEOUT)
{
return_code = OS_QUEUE_TIMEOUT;
}
else
{
/* Something else went wrong */
return_code = OS_ERROR;
OS_DEBUG("Unhandled queue_receive error: %s\n", rtems_status_text(status));
}
}else{
return_code = OS_SUCCESS;
*size_copied = impl_size;
}

return return_code;
Expand Down

0 comments on commit a3ddd01

Please sign in to comment.