Skip to content

Commit 982db6e

Browse files
committed
Fix #1073, refactor SB API for proper global locks
Significant refactor of many SB API calls to address inconsistencies with respect to locking and unlocking of global data structures. First this updates the definition of CFE_SB_PipeId_t to use the CFE_ES_ResourceID_t base type, and a new ID range. Notably this prevents direct access to the CFE_SB.PipeTbl global, forcing code to go through the proper lookup routine, which should only be done while locked. All API implementations follow the same general pattern: - Initial checks/queries while unlocked - Lock SB global - Lookups and/or modifications to the pipe table/routing info - Unlock SB global - Invoke other subsystems (e.g. OSAL) - Re-lock SB global (if needed) do final update, and unlock again - Send all events All error counters should be updated at the end, while still locked. All event processing is deferred to the end of each function, after all other processing is done.
1 parent 1cbdec5 commit 982db6e

File tree

13 files changed

+1860
-1240
lines changed

13 files changed

+1860
-1240
lines changed

fsw/cfe-core/src/inc/cfe_sb.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "cfe_mission_cfg.h"
4444
#include "ccsds.h"
4545
#include "cfe_time.h"
46+
#include "cfe_resourceid.h"
4647

4748

4849
/*
@@ -122,6 +123,13 @@
122123
#define CFE_CLR(i,x) ((i) &= ~CFE_BIT(x)) /**< \brief Clears bit x of i */
123124
#define CFE_TST(i,x) (((i) & CFE_BIT(x)) != 0)/**< \brief true(non zero) if bit x of i is set */
124125

126+
/**
127+
* \brief A CFE_SB_PipeId_t value which is always invalid
128+
*
129+
* This may be used as a safe initializer for CFE_SB_PipeId_t values
130+
*/
131+
#define CFE_SB_INVALID_PIPE CFE_ES_RESOURCEID_UNDEFINED
132+
125133
/*
126134
** Pipe option bit fields.
127135
*/
@@ -164,7 +172,7 @@ typedef uint32 CFE_SB_TimeOut_t;
164172
**
165173
** Software Bus pipe identifier used in many SB APIs
166174
*/
167-
typedef uint8 CFE_SB_PipeId_t;
175+
typedef CFE_ES_ResourceID_t CFE_SB_PipeId_t;
168176

169177
#ifndef CFE_OMIT_DEPRECATED_6_8
170178
/** \brief Pointer to an SB Message */
@@ -264,6 +272,32 @@ CFE_Status_t CFE_SB_CreatePipe(CFE_SB_PipeId_t *PipeIdPtr, uint16 Depth, const
264272
**/
265273
CFE_Status_t CFE_SB_DeletePipe(CFE_SB_PipeId_t PipeId);
266274

275+
/**
276+
* @brief Obtain an index value correlating to an SB Pipe ID
277+
*
278+
* This calculates a zero based integer value that may be used for indexing
279+
* into a local resource table/array.
280+
*
281+
* Index values are only guaranteed to be unique for resources of the same
282+
* type. For instance, the indices corresponding to two [valid] application
283+
* IDs will never overlap, but the index of a pipe ID and an app ID
284+
* may be the same. Furthermore, indices may be reused if a resource is
285+
* deleted and re-created.
286+
*
287+
* @note There is no inverse of this function - indices cannot be converted
288+
* back to the original PipeID value. The caller should retain the original ID
289+
* for future use.
290+
*
291+
* @param[in] PipeID Pipe ID to convert
292+
* @param[out] Idx Buffer where the calculated index will be stored
293+
*
294+
* @return Execution status, see @ref CFEReturnCodes
295+
* @retval #CFE_SUCCESS @copybrief CFE_SUCCESS
296+
* @retval #CFE_ES_ERR_RESOURCEID_NOT_VALID @copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID
297+
*/
298+
CFE_Status_t CFE_SB_PipeId_ToIndex(CFE_SB_PipeId_t PipeID, uint32 *Idx);
299+
300+
267301
/*****************************************************************************/
268302
/**
269303
** \brief Set options on a pipe.

fsw/cfe-core/src/inc/cfe_sb_msg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,14 @@ typedef struct CFE_SB_PipeDepthStats {
604604

605605
CFE_SB_PipeId_t PipeId;/**< \cfetlmmnemonic \SB_PDPIPEID
606606
\brief Pipe Id associated with the stats below */
607-
uint8 Spare;/**< \cfetlmmnemonic \SB_PDSPARE
608-
\brief Spare byte to ensure alignment */
609607
uint16 Depth;/**< \cfetlmmnemonic \SB_PDDEPTH
610608
\brief Number of messages the pipe can hold */
611609
uint16 InUse;/**< \cfetlmmnemonic \SB_PDINUSE
612610
\brief Number of messages currently on the pipe */
613611
uint16 PeakInUse;/**< \cfetlmmnemonic \SB_PDPKINUSE
614612
\brief Peak number of messages that have been on the pipe */
613+
uint16 Spare;/**< \cfetlmmnemonic \SB_PDSPARE
614+
\brief Spare word to ensure alignment */
615615

616616
}CFE_SB_PipeDepthStats_t;
617617

fsw/cfe-core/src/inc/private/cfe_resourceid_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@
6060
* @defgroup CFEResourceIDBase Resource ID base values
6161
* @{
6262
*/
63+
64+
/* ES managed resources */
6365
#define CFE_ES_APPID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+1) << CFE_ES_RESOURCEID_SHIFT))
6466
#define CFE_ES_LIBID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+2) << CFE_ES_RESOURCEID_SHIFT))
6567
#define CFE_ES_COUNTID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+3) << CFE_ES_RESOURCEID_SHIFT))
6668
#define CFE_ES_POOLID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+4) << CFE_ES_RESOURCEID_SHIFT))
6769
#define CFE_ES_CDSBLOCKID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+5) << CFE_ES_RESOURCEID_SHIFT))
6870

71+
/* SB managed resources */
72+
#define CFE_SB_PIPEID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+6) << CFE_ES_RESOURCEID_SHIFT))
73+
6974
/** @} */
7075

7176

0 commit comments

Comments
 (0)