Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling OS_CountSemTimedWait on RTEMS with 0 timeout waits forever #1406

Closed
skliper opened this issue Aug 22, 2023 · 2 comments · Fixed by #1408
Closed

Calling OS_CountSemTimedWait on RTEMS with 0 timeout waits forever #1406

skliper opened this issue Aug 22, 2023 · 2 comments · Fixed by #1408
Labels
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Aug 22, 2023

Describe the bug
See title. Also functional test at osal/src/tests/count-sem-timeout-test.c is missing a 0 timeout test, or this would have been caught.

From https://docs.rtems.org/doxygen/branches/master/group__ClassicSem.html:
rtems_semaphore_obtain - timeout of 0 means wait forever when RTEMS_WAIT option is passed in

To Reproduce
Observed using CF on RTEMS, the flow control semaphore hangs CF if not given. Could reproduce by adding a 0 timeout case to osal/src/tests/count-sem-timeout-test.c.

Expected behavior
Immediate return when passing 0 timeout to OS_CountSemTimedWait. Although not explicit in the OSAL API, it's implied (and how it works for POSIX):

/*-------------------------------------------------------------------------------------*/
/**
* @brief Decrement the semaphore value with timeout
*
* The function locks the semaphore referenced by sem_id. However,
* if the semaphore cannot be locked without waiting for another process
* or thread to unlock the semaphore, this wait shall be terminated when
* the specified timeout, msecs, expires.
*
* @param[in] sem_id The object ID to operate on
* @param[in] msecs The maximum amount of time to block, in milliseconds
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_SEM_TIMEOUT if semaphore was not relinquished in time
* @retval #OS_ERR_INVALID_ID if the ID passed in is not a valid semaphore ID
* @retval #OS_SEM_FAILURE if an unspecified implementation error occurs @covtest
*/
int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs);

Could check if TimeInTicks == 0, pass in RTEMS_NO_WAIT.

Code snips

int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs)
{
rtems_status_code status;
int TimeInTicks;
OS_impl_countsem_internal_record_t *impl;
impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token);
if (OS_Milli2Ticks(msecs, &TimeInTicks) != OS_SUCCESS)
{
return OS_ERROR;
}
status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, TimeInTicks);
if (status == RTEMS_TIMEOUT)
{
return OS_SEM_TIMEOUT;
}
if (status != RTEMS_SUCCESSFUL)
{
OS_DEBUG("Unhandled semaphore_obtain error: %s\n", rtems_status_text(status));
return OS_SEM_FAILURE;
}
return OS_SUCCESS;
}

System observed on:

  • Hardware: GR712RC
  • OS: RTEMS 5
  • Versions: applies to main

Additional context
None.

Reporter Info
Jacob Hageman - NASA/GSFC

@skliper skliper added the bug label Aug 22, 2023
@skliper skliper added this to the Equuleus milestone Aug 22, 2023
skliper added a commit to skliper/osal that referenced this issue Aug 25, 2023
@skliper
Copy link
Contributor Author

skliper commented Aug 25, 2023

Note - also impacts OS_BinSemTimedWait

@skliper
Copy link
Contributor Author

skliper commented Sep 1, 2023

Note - added separate issue to cover adding functional test of 0 timeout to counting and binary semaphore logic:

dzbaker added a commit that referenced this issue Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant