Skip to content

Commit

Permalink
Fix nasa#1386, Refactor initializations of POSIX return_code variab…
Browse files Browse the repository at this point in the history
…les to simplify code
  • Loading branch information
thnkslprpt committed May 4, 2023
1 parent 5036fed commit fecb8df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/os/posix/src/os-impl-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
int attr_created;
int mutex_created;
int cond_created;
int32 return_code;
int32 return_code = OS_SEM_FAILURE;
pthread_mutexattr_t mutex_attr;
OS_impl_binsem_internal_record_t *sem;

Expand Down Expand Up @@ -150,7 +150,6 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n", strerror(ret));
return_code = OS_SEM_FAILURE;
break;
}

Expand All @@ -164,7 +163,6 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n", strerror(ret));
return_code = OS_SEM_FAILURE;
break;
}

Expand All @@ -175,7 +173,6 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutex_init failed: %s\n", strerror(ret));
return_code = OS_SEM_FAILURE;
break;
}

Expand All @@ -188,7 +185,6 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
if (ret != 0)
{
OS_DEBUG("Error: pthread_cond_init failed: %s\n", strerror(ret));
return_code = OS_SEM_FAILURE;
break;
}

Expand All @@ -201,7 +197,6 @@ int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value,
if (ret != 0)
{
OS_DEBUG("Error: initial pthread_cond_signal failed: %s\n", strerror(ret));
return_code = OS_SEM_FAILURE;
break;
}

Expand Down
9 changes: 3 additions & 6 deletions src/os/posix/src/os-impl-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts)
int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype)
{
int ret;
int32 return_code = OS_SUCCESS;
int32 return_code = OS_ERROR;
pthread_mutexattr_t mutex_attr;
OS_impl_objtype_lock_t *impl;

Expand All @@ -200,7 +200,6 @@ int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype)
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n", strerror(ret));
return_code = OS_ERROR;
break;
}

Expand All @@ -211,7 +210,6 @@ int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype)
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n", strerror(ret));
return_code = OS_ERROR;
break;
}

Expand All @@ -223,15 +221,13 @@ int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype)
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutexattr_settype failed: %s\n", strerror(ret));
return_code = OS_ERROR;
break;
}

ret = pthread_mutex_init(&impl->mutex, &mutex_attr);
if (ret != 0)
{
OS_DEBUG("Error: pthread_mutex_init failed: %s\n", strerror(ret));
return_code = OS_ERROR;
break;
}

Expand All @@ -241,9 +237,10 @@ int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype)
if (ret != 0)
{
OS_DEBUG("Error: pthread_cond_init failed: %s\n", strerror(ret));
return_code = OS_ERROR;
break;
}

return_code = OS_SUCCESS;
} while (0);

return return_code;
Expand Down
11 changes: 3 additions & 8 deletions src/os/posix/src/os-impl-timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
osal_index_t idx;
pthread_mutexattr_t mutex_attr;
struct timespec clock_resolution;
int32 return_code;

return_code = OS_SUCCESS;
int32 return_code = OS_ERROR;

do
{
Expand All @@ -215,7 +213,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
if (status != 0)
{
OS_DEBUG("failed in clock_getres: %s\n", strerror(errno));
return_code = OS_ERROR;
break;
}

Expand All @@ -242,7 +239,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
if (status != 0)
{
OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n", strerror(status));
return_code = OS_ERROR;
break;
}

Expand All @@ -253,7 +249,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
if (status != 0)
{
OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n", strerror(status));
return_code = OS_ERROR;
break;
}

Expand All @@ -268,7 +263,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
if (status != 0)
{
OS_DEBUG("Error: Mutex could not be created: %s\n", strerror(status));
return_code = OS_ERROR;
break;
}
}
Expand All @@ -280,7 +274,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
if (OS_SharedGlobalVars.TicksPerSecond <= 0)
{
OS_DEBUG("Error: Unable to determine OS ticks per second: %s\n", strerror(errno));
return_code = OS_ERROR;
break;
}

Expand All @@ -292,6 +285,8 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void)
*/
OS_SharedGlobalVars.MicroSecPerTick =
(1000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / OS_SharedGlobalVars.TicksPerSecond;

return_code = OS_SUCCESS;
} while (0);

return return_code;
Expand Down

0 comments on commit fecb8df

Please sign in to comment.