magiclantern_simplified
magiclantern_simplified copied to clipboard
Trial using event flags for triggering shutdown routines
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.