Skip to content

Commit

Permalink
Fix nasa#1252, add implementation of condition variable API
Browse files Browse the repository at this point in the history
Adds a complete implementation of condition variables for POSIX.
Includes coverage and unit tests.

RTEMS and VxWorks will temporarily use a "no-condvar" placeholder
until an implementation for those systems is added.
  • Loading branch information
jphickey authored and Travis Wheatley committed Sep 16, 2022
1 parent 803a1de commit 5cef02a
Show file tree
Hide file tree
Showing 38 changed files with 2,351 additions and 48 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ set(OSAL_SRCLIST
src/os/shared/src/osapi-binsem.c
src/os/shared/src/osapi-clock.c
src/os/shared/src/osapi-common.c
src/os/shared/src/osapi-condvar.c
src/os/shared/src/osapi-countsem.c
src/os/shared/src/osapi-dir.c
src/os/shared/src/osapi-errors.c
Expand Down Expand Up @@ -357,7 +358,3 @@ else(HAS_PARENT)
# Note that in a CFE/integrated build, it is expected this will be built separately.
add_subdirectory(docs/src docs)
endif(HAS_PARENT)




5 changes: 5 additions & 0 deletions default_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ set(OSAL_CONFIG_MAX_MUTEXES 20
CACHE STRING "Maximum Number of Mutexes to support"
)

# The maximum number of condition variables to support
set(OSAL_CONFIG_MAX_CONDVARS 4
CACHE STRING "Maximum Number of Condition Variables to support"
)

# The maximum number of loadable modules to support
# Note that emulating module loading for statically-linked objects also
# requires a slot in this table, as it still assigns an OSAL ID.
Expand Down
10 changes: 8 additions & 2 deletions osconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@
*/
#define OS_MAX_MUTEXES @OSAL_CONFIG_MAX_MUTEXES@

/**
/**
* \brief The maximum number of condition variables to support
*
* Based on the OSAL_CONFIG_MAX_CONDVARS configuration option
*/
#define OS_MAX_CONDVARS @OSAL_CONFIG_MAX_CONDVARS@

/**
* \brief The maximum number of modules to support
*
* Based on the OSAL_CONFIG_MAX_MODULES configuration option
Expand Down Expand Up @@ -268,4 +275,3 @@


#endif /* OSCONFIG_H */

2 changes: 1 addition & 1 deletion src/os/inc/osapi-condvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int32 OS_CondVarWait(osal_id_t var_id);
* This refers to the same system clock that is the subject of the OS_GetLocalTime() API.
*
* @param[in] var_id The object ID to operate on
* @param[in] abs_wakeup_time The system time at which the task should be unblocked
* @param[in] abs_wakeup_time The system time at which the task should be unblocked @nonnull
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
Expand Down
1 change: 1 addition & 0 deletions src/os/inc/osapi-idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define OS_OBJECT_TYPE_OS_MODULE 0x0A /**< @brief Object module type */
#define OS_OBJECT_TYPE_OS_FILESYS 0x0B /**< @brief Object file system type */
#define OS_OBJECT_TYPE_OS_CONSOLE 0x0C /**< @brief Object console type */
#define OS_OBJECT_TYPE_OS_CONDVAR 0x0D /**< @brief Object condition variable type */
#define OS_OBJECT_TYPE_USER 0x10 /**< @brief Object user type */
/**@}*/

Expand Down
77 changes: 77 additions & 0 deletions src/os/portable/os-impl-no-condvar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file os-impl-no-condvar.c
* \author joseph.p.hickey@nasa.gov
*
* Purpose: All functions return OS_ERR_NOT_IMPLEMENTED.
* This is used when network functionality is disabled by config.
*/

/****************************************************************************************
INCLUDE FILES
***************************************************************************************/

#include <osapi.h>
#include "os-shared-condvar.h"

int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarLock_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarSignal_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarWait_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarDelete_Impl(const OS_object_token_t *token)
{
return OS_ERR_NOT_IMPLEMENTED;
}

int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop)
{
return OS_ERR_NOT_IMPLEMENTED;
}
1 change: 1 addition & 0 deletions src/os/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(POSIX_BASE_SRCLIST
src/os-impl-binsem.c
src/os-impl-common.c
src/os-impl-console.c
src/os-impl-condvar.c
src/os-impl-countsem.c
src/os-impl-dirs.c
src/os-impl-errors.c
Expand Down
42 changes: 42 additions & 0 deletions src/os/posix/inc/os-impl-condvar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* \ingroup posix
*
*/

#ifndef OS_IMPL_CONDVAR_H
#define OS_IMPL_CONDVAR_H

#include "osconfig.h"
#include <pthread.h>

/* CondVares */
typedef struct
{
pthread_mutex_t mut;
pthread_cond_t cv;
} OS_impl_condvar_internal_record_t;

/* Tables where the OS object information is stored */
extern OS_impl_condvar_internal_record_t OS_impl_condvar_table[OS_MAX_CONDVARS];

#endif /* OS_IMPL_CONDVAR_H */
1 change: 1 addition & 0 deletions src/os/posix/inc/os-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ int32 OS_Posix_QueueAPI_Impl_Init(void);
int32 OS_Posix_BinSemAPI_Impl_Init(void);
int32 OS_Posix_CountSemAPI_Impl_Init(void);
int32 OS_Posix_MutexAPI_Impl_Init(void);
int32 OS_Posix_CondVarAPI_Impl_Init(void);
int32 OS_Posix_ModuleAPI_Impl_Init(void);
int32 OS_Posix_TimeBaseAPI_Impl_Init(void);
int32 OS_Posix_StreamAPI_Impl_Init(void);
Expand Down
3 changes: 3 additions & 0 deletions src/os/posix/src/os-impl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ int32 OS_API_Impl_Init(osal_objtype_t idtype)
case OS_OBJECT_TYPE_OS_FILESYS:
return_code = OS_Posix_FileSysAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_CONDVAR:
return_code = OS_Posix_CondVarAPI_Impl_Init();
break;
default:
break;
}
Expand Down
Loading

0 comments on commit 5cef02a

Please sign in to comment.