Add ConcurrentReadingMonitor for access to some data where at any given time, we can have several readers but no writer, or one writer and no readers.
Add ReadGuard and WriteGuard to call the respective entry and exit procedures of a monitor automatically based on the scope.
Add READ_GUARD and WRITE_GUARD macros to allow for abstracting the check whether threads are disabled or not.
Basically, I had some theory about this in class and thought why not try it out somewhere. ~I think the changes I made won't hurt, and may even solve some potential issues. Namely, the following trace in the CANNetworkManager would currently have let to a deadlock: process_any_control_function_pgn_callbacks() -> some code in callback... -> remove_any_control_function_parameter_group_number_callback() - here the code would try to lock an already locked mutex with no way it will get unlocked after. So even though it may be overkill to allow for multiple readers, it could still be a valuable addition.~
Also, the data_monitor files allows for easy expansion with other monitors to satisfy some other synchronization invariant. While keeping it modular to integrate anywhere as we handle the "disable thread" functionality in the implementation as well.
How has this been tested?
I ran the unit-tests and VT3 example with threads enabled. And a slightly-modified VT3 example with threads disabled.
Describe your changes
ConcurrentReadingMonitor
for access to some data where at any given time, we can have several readers but no writer, or one writer and no readers.ReadGuard
andWriteGuard
to call the respective entry and exit procedures of a monitor automatically based on the scope.READ_GUARD
andWRITE_GUARD
macros to allow for abstracting the check whether threads are disabled or not.Basically, I had some theory about this in class and thought why not try it out somewhere. ~I think the changes I made won't hurt, and may even solve some potential issues. Namely, the following trace in the CANNetworkManager would currently have let to a deadlock:
process_any_control_function_pgn_callbacks()
-> some code in callback... ->remove_any_control_function_parameter_group_number_callback()
- here the code would try to lock an already locked mutex with no way it will get unlocked after. So even though it may be overkill to allow for multiple readers, it could still be a valuable addition.~Also, the data_monitor files allows for easy expansion with other monitors to satisfy some other synchronization invariant. While keeping it modular to integrate anywhere as we handle the "disable thread" functionality in the implementation as well.
How has this been tested?
I ran the unit-tests and VT3 example with threads enabled. And a slightly-modified VT3 example with threads disabled.