The microbit fiber scheduler is often used to service event handlers by the microbit message bus.
This provides a very elegant decoupling of user code from system code, interrupt handlers and
also allows users to make blocking calls within event handlers. However, many event handlers are
non-blocking, so launching a dedicated fiber is wasteful in terms of time and SRAM.
This patch adds fork_on_block() to the scheduler. Inspired by the UNIX copy_on_write
technique, this optimisation is semantically equivalent to a create_fiber() call, but will first attempt
to execute the given function in the context of the currently running fiber, and *only* create a fiber
if the given code attempts a blocking operation.
More specifically, this update:
- adds fork_on_block() functions for parameterised and non-parameterised functions.
- adds fields to the fiber context to record the status of parent/child fibers.
- adds optimised ASM functions to store and restore Cortex M0 register context.
- adds a utility function to determine if the processor is executing in interrupt context.
- updates to sleep() and wait_for_event() to handle fork_on_block semantics.
- minor code optimsations within the scheduler.
This is the first commit of the microbit-dal on GitHub.
This repository contains the runtime, which is a light
weight operating system developed by Lancaster University.