Skip to content

Commit

Permalink
Merge branches 'fix-1073-sb-locking' and 'fix-1090-ut-eventcheck-boun…
Browse files Browse the repository at this point in the history
…ds' into jph-wip-baseline-20210115
  • Loading branch information
jphickey committed Jan 15, 2021
3 parents c7363c8 + b17cd1e + ad9ae56 commit 0f4ed8f
Show file tree
Hide file tree
Showing 28 changed files with 2,356 additions and 1,502 deletions.
16 changes: 9 additions & 7 deletions fsw/cfe-core/src/es/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1877,9 +1877,11 @@ int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle)
return CFE_ES_CDSBlockRead(RestoreToMemory, Handle);
} /* End of CFE_ES_RestoreFromCDS() */

/* end of file */


/*
** Function: CFE_ES_RegisterGenCounter
**
** Purpose: Allocates a generic counter resource and assigns ID
*/
int32 CFE_ES_RegisterGenCounter(CFE_ES_ResourceID_t *CounterIdPtr, const char *CounterName)
{
CFE_ES_GenCounterRecord_t *CountRecPtr;
Expand Down Expand Up @@ -1912,7 +1914,7 @@ int32 CFE_ES_RegisterGenCounter(CFE_ES_ResourceID_t *CounterIdPtr, const char *C
else
{
/* scan for a free slot */
PendingCounterId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastCounterId, CFE_PLATFORM_ES_MAX_GEN_COUNTERS);
PendingCounterId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastCounterId, CFE_PLATFORM_ES_MAX_GEN_COUNTERS, CFE_ES_CheckCounterIdSlotUsed);
CountRecPtr = CFE_ES_LocateCounterRecordByID(PendingCounterId);

if (CountRecPtr == NULL)
Expand Down Expand Up @@ -2108,7 +2110,7 @@ CFE_Status_t CFE_ES_GetGenCounterName(char *CounterName, CFE_ES_ResourceID_t Cou
*/
int32 CFE_ES_AppID_ToIndex(CFE_ES_ResourceID_t AppID, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex_Internal(
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(AppID) - CFE_ES_APPID_BASE,
CFE_PLATFORM_ES_MAX_APPLICATIONS,
Idx);
Expand All @@ -2120,7 +2122,7 @@ int32 CFE_ES_AppID_ToIndex(CFE_ES_ResourceID_t AppID, uint32 *Idx)
*/
int32 CFE_ES_LibID_ToIndex(CFE_ES_ResourceID_t LibId, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex_Internal(
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(LibId) - CFE_ES_LIBID_BASE,
CFE_PLATFORM_ES_MAX_LIBRARIES,
Idx);
Expand Down Expand Up @@ -2160,7 +2162,7 @@ int32 CFE_ES_TaskID_ToIndex(CFE_ES_ResourceID_t TaskID, uint32 *Idx)
*/
int32 CFE_ES_CounterID_ToIndex(CFE_ES_ResourceID_t CounterId, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex_Internal(
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(CounterId) - CFE_ES_COUNTID_BASE,
CFE_PLATFORM_ES_MAX_GEN_COUNTERS,
Idx);
Expand Down
5 changes: 3 additions & 2 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr,
else
{
/* scan for a free slot */
PendingAppId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastAppId, CFE_PLATFORM_ES_MAX_APPLICATIONS);
PendingAppId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastAppId, CFE_PLATFORM_ES_MAX_APPLICATIONS, CFE_ES_CheckAppIdSlotUsed);
AppRecPtr = CFE_ES_LocateAppRecordByID(PendingAppId);

if (AppRecPtr == NULL)
Expand Down Expand Up @@ -795,6 +795,7 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr,
return Status;

} /* End Function */

/*
**---------------------------------------------------------------------------------------
** Name: CFE_ES_LoadLibrary
Expand Down Expand Up @@ -864,7 +865,7 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr,
else
{
/* scan for a free slot */
PendingLibId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastLibId, CFE_PLATFORM_ES_MAX_LIBRARIES);
PendingLibId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastLibId, CFE_PLATFORM_ES_MAX_LIBRARIES, CFE_ES_CheckLibIdSlotUsed);
LibSlotPtr = CFE_ES_LocateLibRecordByID(PendingLibId);

if (LibSlotPtr == NULL)
Expand Down
16 changes: 14 additions & 2 deletions fsw/cfe-core/src/es/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,24 @@ int32 CFE_ES_CDS_EarlyInit(void)
/*******************************************************************/
int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex_Internal(
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(BlockID) - CFE_ES_CDSBLOCKID_BASE,
CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES,
Idx);
}

/*---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckCDSBlockIdSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given ID is available. Must be called while locked.
*---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckCDSBlockIdSlotUsed(CFE_ES_ResourceID_t CheckId)
{
return CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CheckId));
}

/*******************************************************************/
/*
* CFE_ES_LocateCDSBlockRecordByID
Expand Down Expand Up @@ -347,7 +359,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, size_t UserBlockSize,
else
{
/* scan for a free slot */
PendingBlockId = CFE_ES_FindNextAvailableId(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES);
PendingBlockId = CFE_ES_FindNextAvailableId(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES, CFE_ES_CheckCDSBlockIdSlotUsed);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(PendingBlockId);

if (RegRecPtr != NULL)
Expand Down
14 changes: 14 additions & 0 deletions fsw/cfe-core/src/es/cfe_es_cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ static inline size_t CFE_ES_CDSBlockRecordGetUserSize(const CFE_ES_CDS_RegRec_t
return (CDSBlockRecPtr->BlockSize - sizeof(CFE_ES_CDS_BlockHeader_t));
}

/**
* @brief Check if a CDS Block ID table slot is used
*
* Checks if a table slot is available for a potential new ID
* This is a helper function intended to be used with
* CFE_ES_FindNextAvailableID() for allocating new IDs
*
* As this dereferences fields within the record, global data must be
* locked prior to invoking this function.
*
* @param[in] CheckId pending/candidate Block ID to check
* @returns true if the table slot for the ID is occupied, false if available
*/
bool CFE_ES_CheckCDSBlockIdSlotUsed(CFE_ES_ResourceID_t CheckId);

/*****************************************************************************/
/**
Expand Down
16 changes: 14 additions & 2 deletions fsw/cfe-core/src/es/cfe_es_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,24 @@ int32 CFE_ES_MemPoolDirectCommit(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offs

int32 CFE_ES_MemPoolID_ToIndex(CFE_ES_MemHandle_t PoolID, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex_Internal(
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(PoolID) - CFE_ES_POOLID_BASE,
CFE_PLATFORM_ES_MAX_MEMORY_POOLS,
Idx);
}

/*---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckMemPoolSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given table slot is available. Must be called while locked.
*---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckMemPoolSlotUsed(CFE_ES_ResourceID_t CheckId)
{
return CFE_ES_MemPoolRecordIsUsed(CFE_ES_LocateMemPoolRecordByID(CheckId));
}

CFE_ES_MemPoolRecord_t* CFE_ES_LocateMemPoolRecordByID(CFE_ES_MemHandle_t PoolID)
{
CFE_ES_MemPoolRecord_t *MemPoolRecPtr;
Expand Down Expand Up @@ -211,7 +223,7 @@ int32 CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t *PoolID,
CFE_ES_LockSharedData(__func__,__LINE__);

/* scan for a free slot */
PendingID = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastMemPoolId, CFE_PLATFORM_ES_MAX_MEMORY_POOLS);
PendingID = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastMemPoolId, CFE_PLATFORM_ES_MAX_MEMORY_POOLS, CFE_ES_CheckMemPoolSlotUsed);
PoolRecPtr = CFE_ES_LocateMemPoolRecordByID(PendingID);

if (PoolRecPtr == NULL)
Expand Down
28 changes: 27 additions & 1 deletion fsw/cfe-core/src/es/cfe_es_mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,38 @@ static inline void CFE_ES_MemPoolRecordSetFree(CFE_ES_MemPoolRecord_t *PoolRecPt
PoolRecPtr->PoolID = CFE_ES_RESOURCEID_UNDEFINED;
}


/**
* @brief Check if an Mem Pool record is a match for the given Pool ID
*
* This routine confirms that the previously-located record is valid
* and matches the expected Pool ID.
*
* As this dereferences fields within the record, global data must be
* locked prior to invoking this function.
*
* @param[in] PoolRecPtr pointer to Pool table entry
* @param[in] PoolID expected Pool ID
* @returns true if the entry matches the given pool ID
*/
static inline bool CFE_ES_MemPoolRecordIsMatch(const CFE_ES_MemPoolRecord_t *PoolRecPtr, CFE_ES_MemHandle_t PoolID)
{
return (PoolRecPtr != NULL && CFE_ES_ResourceID_Equal(PoolRecPtr->PoolID, PoolID));
}

/**
* @brief Check if a Pool ID table slot is used
*
* Checks if a table slot is available for a potential new ID
* This is a helper function intended to be used with
* CFE_ES_FindNextAvailableID() for allocating new IDs
*
* As this dereferences fields within the record, global data must be
* locked prior to invoking this function.
*
* @param[in] CheckId pending/candidate Pool ID to check
* @returns true if the table slot for the ID is occupied, false if available
*/
bool CFE_ES_CheckMemPoolSlotUsed(CFE_ES_ResourceID_t CheckId);


#endif /* _CFE_ES_MEMPOOL_H_ */
67 changes: 43 additions & 24 deletions fsw/cfe-core/src/es/cfe_es_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

/*********************************************************************/
/*
* CFE_ES_ResourceID_ToIndex_Internal
* CFE_ES_ResourceID_ToIndex
*
* For complete API information, see prototype in header
*/
int32 CFE_ES_ResourceID_ToIndex_Internal(uint32 Serial, uint32 TableSize, uint32 *Idx)
int32 CFE_ES_ResourceID_ToIndex(uint32 Serial, uint32 TableSize, uint32 *Idx)
{
if (Idx == NULL)
{
Expand Down Expand Up @@ -94,7 +94,7 @@ CFE_ES_ResourceID_t CFE_ES_ResourceID_FromOSAL(osal_id_t id)
*
* For complete API information, see prototype in header
*/
CFE_ES_ResourceID_t CFE_ES_FindNextAvailableId(CFE_ES_ResourceID_t StartId, uint32 TableSize)
CFE_ES_ResourceID_t CFE_ES_FindNextAvailableId(CFE_ES_ResourceID_t StartId, uint32 TableSize, bool (*CheckFunc)(CFE_ES_ResourceID_t))
{
uint32 Serial;
uint32 Count;
Expand Down Expand Up @@ -124,27 +124,7 @@ CFE_ES_ResourceID_t CFE_ES_FindNextAvailableId(CFE_ES_ResourceID_t StartId, uint
}
CheckId = CFE_ES_ResourceID_FromInteger(ResourceType + Serial);

switch (ResourceType)
{
case CFE_ES_APPID_BASE:
IsTaken = CFE_ES_AppRecordIsUsed(CFE_ES_LocateAppRecordByID(CheckId));
break;
case CFE_ES_LIBID_BASE:
IsTaken = CFE_ES_LibRecordIsUsed(CFE_ES_LocateLibRecordByID(CheckId));
break;
case CFE_ES_COUNTID_BASE:
IsTaken = CFE_ES_CounterRecordIsUsed(CFE_ES_LocateCounterRecordByID(CheckId));
break;
case CFE_ES_POOLID_BASE:
IsTaken = CFE_ES_MemPoolRecordIsUsed(CFE_ES_LocateMemPoolRecordByID(CheckId));
break;
case CFE_ES_CDSBLOCKID_BASE:
IsTaken = CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CheckId));
break;
default:
/* do nothing, should never happen */
break;
}
IsTaken = CheckFunc(CheckId);
}
while (IsTaken);

Expand Down Expand Up @@ -430,4 +410,43 @@ CFE_ES_AppRecord_t *CFE_ES_GetAppRecordByContext(void)
return AppRecPtr;
}

/*
* ---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckCounterIdSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given ID is available. Must be called while locked.
* ---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckCounterIdSlotUsed(CFE_ES_ResourceID_t CheckId)
{
return CFE_ES_CounterRecordIsUsed(CFE_ES_LocateCounterRecordByID(CheckId));
}

/*
*---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckAppIdSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given ID is available. Must be called while locked.
*---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckAppIdSlotUsed(CFE_ES_ResourceID_t CheckId)
{
return CFE_ES_AppRecordIsUsed(CFE_ES_LocateAppRecordByID(CheckId));
}

/*
* ---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckLibIdSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given ID is available. Must be called while locked.
* ---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckLibIdSlotUsed(CFE_ES_ResourceID_t CheckId)
{
return CFE_ES_LibRecordIsUsed(CFE_ES_LocateLibRecordByID(CheckId));
}


Loading

0 comments on commit 0f4ed8f

Please sign in to comment.