I would do 2 things to check your code. A thorough group review of the code (in order to search for re-entry errors, not style or other errors). Secondly, a practical attack on problems.
For instance:
int myfunction(int x, int y) { REENTRANCE_CHECK; ... body of function }
Now you can #define REENTRANCE_CHECK be either empty (for production) or some code that checks that the function is never re-entered. Run your tests (if you don't have tests, then run them on your device with an attached debugger) if these checks are enabled, and see if something happens.
Similarly, you can add debug logic to detect incorrect updates in the global state. Write code that uses locks (which claim if they were acquired when they were already saved.
Something like that:
int my_global; DEFINE_GLOBAL_LOCK(my_global); void my_dangerous_function() { ... LOCK_GLOBAL(my_global); .. some critical section of code that uses my_global. UNLOCK_GLOBAL(my_global); ... }
Again, DECLARE_GLOBAL_LOCK, LOCK_GLOBAL and UNLOCK_GLOBAL can either be #defined to be the real lock code (which, of course, you will have to write) for testing, and for production they can be # undefined.
This approach only works if you find and complete all calls to your global state, but it is easy with a search.
user97370
source share