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

CFE_SB_Default_Qos exposed globally, with internal defaults, passing structure by value #1123

Closed
skliper opened this issue Jan 25, 2021 · 4 comments · Fixed by #1125 or #1150
Closed
Assignees
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Jan 25, 2021

Is your feature request related to a problem? Please describe.
CFE_SB_Default_Qos is extern from cfe_sb.h (so any code including cfe_sb.h could change it's value!):

/** \brief Quality Of Service Type Definition
**
** Currently an unused parameter in #CFE_SB_SubscribeEx
** Intended to be used for interprocessor communication only
**/
typedef struct {
uint8 Priority;/**< \brief Specify high(1) or low(0) message priority for off-board routing, currently unused */
uint8 Reliability;/**< \brief Specify high(1) or low(0) message transfer reliability for off-board routing, currently unused */
}CFE_SB_Qos_t;
extern CFE_SB_Qos_t CFE_SB_Default_Qos;/**< \brief Defines a default priority and reliabilty for off-board routing */

But the defines are "internal" to SB:

#define CFE_SB_QOS_LOW_PRIORITY 0
#define CFE_SB_QOS_LOW_RELIABILITY 0

Also structure passed by value:

CFE_Status_t CFE_SB_SubscribeEx(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId, CFE_SB_Qos_t Quality, uint16 MsgLim);

There is no underlying implementation, so currently just a placeholder in the API.

Describe the solution you'd like
Possibly convert to bits in a uint32/16 or similar (structure is overkill), provide default and the other values publicly as defines, don't expose as a global variable.

Describe alternatives you've considered
None

Additional context
Found when working #1036, it's out of family since it's not at task global scope.

Requester Info
Jacob Hageman

@skliper skliper added this to the 7.0.0 milestone Jan 25, 2021
@skliper
Copy link
Contributor Author

skliper commented Jan 25, 2021

@ejtimmon Note CFE_SB_Default_Qos is referenced by ds and hs (and in sch test utils)

@skliper skliper self-assigned this Jan 25, 2021
@jphickey
Copy link
Contributor

Passing by value is generally OK so long as the structure is small (i.e. 32 bits or less) in case the calling convention in use relies on register(s) to pass argument/return values. However if it grows larger it can become inefficient to pass by value.

IIRC the one I was worried about before was CFE_TIME_SysTime_t - this is passed by value and it is 64 bits in size, therefore could be inefficient on 32-bit machines depending on the calling convention and particularly the return value.

But this one is only 16 bits so its probably fine. But it would be a good idea to note in the structure/declaration comments that it is passed by value and therefore needs to be kept small for this reason - so fields shouldn't be added without careful consideration.

@skliper
Copy link
Contributor Author

skliper commented Jan 25, 2021

I understand it's OK in this case since it's small, but the extra caution/complexity and currently implementation really doesn't seem justifiable based on a lack of implementation. I'd think a generic uint and setting bits is a more flexible, future proof implementation that needs no special note. Could easily add implementations as modules and assign more bits (or have reserved/user defined bits), etc without having to redefine the elements in the structure (until bits run out).

@jphickey
Copy link
Contributor

jphickey commented Jan 25, 2021

Sure, bit fields in an integer could work too - but then you lose the advantage of type safety protection from having it as a struct. That is, one has to declare their local variable as a CFE_SB_Qos_t or else they get a type mismatch when they try to pass it to the API. If it is uint32 then any integer will be accepted - regardless of whether the value is actually compatible or not (including short/long/signed/unsigned/literals - pretty much anything).

I definitely agree with moving the constants out of the "private" file and into a public header file - but I would hesitate to actually change the API at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants