Hi there,
I'm refactoring a program that deals with a lot of variables being asynchronously shared among different Tasks.
This is done enclosing them with spinlocks functions this way:
C++:
portENTER_CRITICAL(mux);
SharedVariable1 = value1;
// ...
SharedVariableN = valueN;
portEXIT_CRITICAL(mux);
So far so good, but there are a lot of those constructs spread in the code, most of them to protect a single assignment.
I was considering to create a function to do that, and this is the first thing that came to mind:
C++:
void ProtectedAssignStrVar ( const String origin,
String &destination,
portMUX_TYPE *mux )
{
portENTER_CRITICAL(mux);
destination = origin;
portEXIT_CRITICAL(mux);
}
...which should be used this way:
C++:
String ValueOrigin = "Example";
String VariableDestinationShared;
ProtectedAssignStr( sharedOrigin,
sharedDestination,
muxSolenoid )
The problem here is that I fear this wont work because something tells me that the capture of the value in the function argument will take place before entering the safe section itself.
Ok, one could suggest to create a function containing all these global variables within, assigning their value upon a
switch...case selector, but I would like to avoid creating more supporting structures that could make the program less intelligible.
So could you give your insights on this, if there is any other alternative ?
( maybe...by using funtion pointer, whatever )