From b708d5d9c973730c6fb24c6c83850ec7bfc49585 Mon Sep 17 00:00:00 2001 From: Sam Price Date: Thu, 22 Sep 2022 13:49:31 -0400 Subject: [PATCH 1/2] Fix #1279, Switch rtems queue to mimic posix logic. --- src/os/rtems/src/os-impl-queues.c | 68 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c index aed05a03b..3dbd878d2 100644 --- a/src/os/rtems/src/os-impl-queues.c +++ b/src/os/rtems/src/os-impl-queues.c @@ -156,12 +156,13 @@ int32 OS_QueueDelete_Impl(const OS_object_token_t *token) *-----------------------------------------------------------------*/ int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - rtems_status_code status; - rtems_interval ticks; - int tick_count; - rtems_option option_set; - size_t rtems_size; + int32 return_code; + rtems_status_code status; + rtems_interval ticks; + int tick_count; + rtems_option option_set; + /* Implementation read size */ + size_t impl_size; rtems_id rtems_queue_id; OS_impl_queue_internal_record_t *impl; @@ -198,46 +199,43 @@ 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 + if (status != RTEMS_SUCCESSFUL) { - /* Something else went wrong */ - return_code = OS_ERROR; - OS_DEBUG("Unhandled queue_receive error: %s\n", rtems_status_text(status)); - } + *size_copied = 0; - /* - ** Check the size of the message. If a valid message was - ** obtained, indicate success. - */ - if (status == RTEMS_SUCCESSFUL) - { - *size_copied = rtems_size; - if (rtems_size != size) + /* 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) { - /* Success, but the size was wrong */ - return_code = OS_QUEUE_INVALID_SIZE; + 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 { - *size_copied = 0; + *size_copied = impl_size; + return_code = OS_SUCCESS; } return return_code; From 2f2dbacd4112570892264165e702159a434f05b3 Mon Sep 17 00:00:00 2001 From: Sam Price Date: Thu, 29 Sep 2022 17:05:00 -0400 Subject: [PATCH 2/2] Fix #1279, update size_copied to use OSAL_SIZE_C for cast. --- src/os/rtems/src/os-impl-queues.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c index 3dbd878d2..da84ee508 100644 --- a/src/os/rtems/src/os-impl-queues.c +++ b/src/os/rtems/src/os-impl-queues.c @@ -206,7 +206,7 @@ int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, if (status != RTEMS_SUCCESSFUL) { - *size_copied = 0; + *size_copied = OSAL_SIZE_C(0); /* Map the rtems error to the most appropriate OSAL return code */ if ((timeout == OS_PEND) && (status != RTEMS_TIMEOUT)) @@ -234,7 +234,7 @@ int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, } else { - *size_copied = impl_size; + *size_copied = OSAL_SIZE_C(impl_size); return_code = OS_SUCCESS; }