fork

Dependencies:   BLE_API mbed-dev-bin nRF51822

Dependents:   microbit

Fork of microbit-dal by Lancaster University

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Thu Apr 07 11:59:19 2016 +0100
Parent:
4:9fbeeb89de59
Child:
6:2e1c2e0d8c7a
Commit message:
Synchronized with git rev 72d2d2b1
Author: Joe Finney
microbit: MessageBus now treats all listeners as MESSAGE_BUS_LISTENER_IMMEDIATE if no scheduler is present

The default THREADING_MODE for event handlers is typically set to run through
the scheduler. However, it is possible to create and operate a MessageBus without the scheduler being initialised.

This patch changes the behaviour of the MessageBus to treat all registered
listeners as MESSAGE_BUS_LISTENER_IMMEDIATE (i.e. directly called) if no
scheduler is present. This default allows for a more user friendly experience
in this case.

Changed in this revision

source/drivers/MicroBitMessageBus.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/drivers/MicroBitMessageBus.cpp	Thu Apr 07 11:59:17 2016 +0100
+++ b/source/drivers/MicroBitMessageBus.cpp	Thu Apr 07 11:59:19 2016 +0100
@@ -358,7 +358,14 @@
     {
 	    if((l->id == evt.source || l->id == MICROBIT_ID_ANY) && (l->value == evt.value || l->value == MICROBIT_EVT_ANY))
         {
-            listenerUrgent = (l->flags & MESSAGE_BUS_LISTENER_IMMEDIATE) == MESSAGE_BUS_LISTENER_IMMEDIATE;
+            // If we're running under the fiber scheduler, then derive the THREADING_MODE for the callback based on the
+            // metadata in the listener itself.
+            if (fiber_scheduler_running())
+                listenerUrgent = (l->flags & MESSAGE_BUS_LISTENER_IMMEDIATE) == MESSAGE_BUS_LISTENER_IMMEDIATE;
+            else
+                listenerUrgent = true;
+
+            // If we should process this event hander in this pass, then activate the listener.
             if(listenerUrgent == urgent && !(l->flags & MESSAGE_BUS_LISTENER_DELETING))
             {
                 l->evt = evt;
@@ -549,4 +556,4 @@
 MicroBitMessageBus::~MicroBitMessageBus()
 {
     fiber_remove_idle_component(this);
-}
+}
\ No newline at end of file