reticulatedpines / magiclantern_simplified

A Git based version of Magic Lantern, for those unwilling or unable to work using Mercurial. The vast majority of branches have been removed, with those thought to be important brought in individually and merged.
GNU General Public License v2.0
142 stars 47 forks source link

Trial using event flags for triggering shutdown routines #142

Open reticulatedpines opened 3 months ago

reticulatedpines commented 3 months ago

On ML shutdown we want to run various pieces of cleanup code, scattered across the code base. The core of this is in ml_shutdown(), which sets a global variable.

This is not very reliable or convenient, since code must poll for change of that variable. And if you're waiting on a sem, for example, you won't wake in order to check the global. This also relates to TASK_LOOP, which hides a check against ml_shutdown_requested. This is itself ugly; the intent is hidden. And most uses of TASK_LOOP do no cleanup code when the loop exits, so it's pointless.

This is probably why miscellaneous functions are called directly by ml_shutdown().

DryOS has a mechanism for low-latency, simple message broadcast; event flags. It should be cleaner, more reliable, and more efficient, to replace most checks against ml_shutdown_requested with waits for changes to a shutdown event flag. ml_shutdown() sets a flag, any cleanup code immediately triggers.