Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce optional javascript semantics for event handling #418

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

tballmsft
Copy link
Contributor

  • new CONFIG option now allows the user to choose between ordered, serial
    processing of event handlers and parallel execution of events (JS
    semantics) OR parallel processing of event handlers and serial execution of
    events (legacy mciro:bit semantics)

  • Introduciton of a MicroBitLock primitive for mutual exclusion

  - new CONFIG option now allows the user to choose between ordered, serial
    processing of event handlers and parallel execution of events (JS
semantics) OR parallel processing of event handlers and serial execution of
events (legacy mciro:bit semantics)

  - Introduciton of a MicroBitLock primitive for mutual exclusion
@tballmsft
Copy link
Contributor Author

guys - can you please merge this work into master?

 - First character of string is now printed on next frame update, rather than
   waiting for an inter-character gap

 - No unecessary delay after the final character is printed.

These changes make the print() semantics align with the image animate()
semantics.
Align fork-on-block implementation of fiber_wake_on_event() with that of fiber_sleep() and MicroBitLock::wait().

This patch has no impact on external behaviour, but introduces a consistent
deisgn pattern for fork-on-block handling within the scheduler.
Updated parameters of this internal method to pass the event being processed
by value, rather than by reference. This is important for applications using
the MESSAGE_BUS_CONCURRENT_EVENTS concurrency mode (JavaScript semantics) to
ensure that any multiple event handlers registered for the same event maintain
a persistent copy of that event on the relevant fiber stack.
Update to the internal  MicroBitDisplay::waitForFreeDisplay() method to ensure
that fibers queued waiting for access to the display always re-contest for
access, thereby avoiding potnetial race conditions.
@@ -108,7 +108,7 @@ class MicroBitMessageBus : public EventModel, public MicroBitComponent
* @note It is recommended that all external code uses the send() function instead of this function,
* or the constructors provided by MicrobitEvent.
*/
int process(MicroBitEvent &evt, bool urgent = false);
int process(MicroBitEvent evt, bool urgent = false);
Copy link
Contributor

@jamesadevine jamesadevine Feb 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@finneyj what's the overhead implications of this change?

@finneyj
Copy link
Contributor

finneyj commented Feb 27, 2019

Stack sizes will be a few bytes larger, and there'll be one more copy operation during top level processing of each event raise, so a few more microseconds.

finneyj and others added 20 commits May 3, 2019 17:06
  - Replace doubly linked list of Fibers with singly-linked equivalent to
    reduce memory footprint.
  - Create a new FiberTable structure, that record all active fibers
  - Update fiber creation/deletion code to maintain the table
  - Add a utility function to allow read access to the table
  - Introduce a CONFIG option to define the initial FiberTable size
  - Add new CONFIG option to enable per-fiber meta data (default: disabled)
  - Add (void *) pointer to Fiber struct when CONFIG option enabled
  - Add Yotta CONFIG glue
  - Refactor fork-on-block handling into a unified function
  - Align validation semantics of both flavours of invoke() function
  - Replace accidentally deleted validation check in fiber_sleep().
  - Remove FiberTable structure
  - Remove CONFIG options and mappings relating to table size
  - Add new list linkage to Fiber structure to maintain list of all Fibers
  - Replace get_fiber_table() with get_fiber_list()
Also port from codal-core in support of PXT GC.
Also, fix compiler optimization bug in calloc().
  - new CONFIG option now allows the user to choose between ordered, serial
    processing of event handlers and parallel execution of events (JS
semantics) OR parallel processing of event handlers and serial execution of
events (legacy mciro:bit semantics)

  - Introduciton of a MicroBitLock primitive for mutual exclusion
 - First character of string is now printed on next frame update, rather than
   waiting for an inter-character gap

 - No unecessary delay after the final character is printed.

These changes make the print() semantics align with the image animate()
semantics.
Updated parameters of this internal method to pass the event being processed
by value, rather than by reference. This is important for applications using
the MESSAGE_BUS_CONCURRENT_EVENTS concurrency mode (JavaScript semantics) to
ensure that any multiple event handlers registered for the same event maintain
a persistent copy of that event on the relevant fiber stack.
Update to the internal  MicroBitDisplay::waitForFreeDisplay() method to ensure
that fibers queued waiting for access to the display always re-contest for
access, thereby avoiding potnetial race conditions.
This is port of relevant codal changes in support of GC in the
PXT runtime.
Also, limit the number of fibers in pool to 3.
Also port from codal-core in support of PXT GC.
Also, fix compiler optimization bug in calloc().
 - Rename pointers in Fiber struct to be more intuitive.
finneyj and others added 11 commits March 25, 2020 16:03
  - Remove redundant API
  - superceded by get_fiber_list()
  - Update component ID values to align with those used in CODAL
  - Just enables some code cleanup within MakeCode.
  - MicroBitSerial use wake_on_event for condition synchronisation.
  - By contract, a fiber doing this should subsequently call schedule()
    and no other blocking operation
  - Simplify behaviour of print() and printAsync() methods.
  - print(char) print(ManagedString) and print(MicroBitImage) now all have same semantics:

    - If provided, the delay parameter is always respected. Screen is cleared after that time.

    - discrete print operations (character, string of length 1 and MicroBitImage) with no
      delay parameter are printed, and return immeditely. The screen is not cleared.

    - print (string of length > 1) with no delay parameter defaults to a delay
      of MICROBIT_DEFAULT_PRINT_SPEED milliseconds. The screen is cleared on
      completion.
  - fix regression in semantics
  - all print() operation of unit length now leave the screen uncleared, even
    when a duration is provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants