Skip to content

0021: ext_ui_lock waits while a stock SysEx goes out (no message inside a dump) - #33

Open
twwwy wants to merge 1 commit into
trigcondition:devfrom
twwwy:fix/ui-lock-sysex
Open

twwwy wants to merge 1 commit into
trigcondition:devfrom
twwwy:fix/ui-lock-sysex

Conversation

@twwwy

@twwwy twwwy commented Nov 23, 2026 •

Copy link
Copy Markdown

Found while testing big RAM (#32). It's a fix to dev's 0021 and stands on its own.

The bug

us_send (the 19 ASK and the 1C write-backs) takes the MIDI mutex with ext_ui_lock. That function checks the port, the ring's room and the free requests. Unlike ext_try_send, it doesn't check SYSEX_STATE. In rytm-emu (1.74, sq_emu fillqueue), a 19 ASK landed 12 bytes before the end of a 14,988-byte stock pattern dump, and the dump's tail was lost: the host got 6 whole answers of 7.

On dev the test passes only because of the tick timing. The big-RAM series moves 0026's start-up by 3 ticks and 0029's by 1, and then it fails every time. Two controls show the timing exposes the race rather than causing it:

  • dev plus the same amount of dead code still passes;
  • big RAM without its per-tick checks still fails.

The fix

ext_ui_lock also returns 0 while SYSEX_STATE is set. The caller asks again on a later tick, as it already does for a full ring. +8 B of code.

I haven't traced why the mutex was free inside the dump.

Tests

sq_emu fillqueue passes with this on top of big RAM, all checks. With this fix alone on dev (Makefile release set, tag u33, verify PASS): suites.py u33 --changed upstream/dev picks 12 suites (us sfu md sq cu sv ar sp mi pc mrep sa44), all with the same counts as dev. +8 B.

🤖 Generated with Claude Code

…de a dump)

us_send (19 ASK, 1C write-backs) took the MIDI mutex with ext_ui_lock,
which checked the port, the ring's room and the free requests but not
SYSEX_STATE, as ext_try_send does. In rytm-emu (1.74, sq_emu
fillqueue, with the timing the big-ram series gives the ticks) a 0x19
ASK landed 12 bytes before the end of a 14,988-byte pattern dump, and
the dump's tail was lost: the host got 6 whole answers of 7.

ext_ui_lock now also returns 0 while SYSEX_STATE is set; the caller asks
again on a later tick, as it does for a full ring. +8 B of code.

Why the mutex was free inside the dump is not traced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant