]> git.sesse.net Git - nageru/commit
Fix a deadlock in Futatabi when using MIDI devices.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Feb 2020 22:25:11 +0000 (23:25 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Feb 2020 22:25:11 +0000 (23:25 +0100)
commitf61426b86c37f873a52f0440537df8f9a35562a4
tree1fb9ca6e2ffce0149aa08a247ae5661b6241aa21
parent1bf2b3e600dc5485f4957a419459b997d721e5fa
Fix a deadlock in Futatabi when using MIDI devices.

If something in the UI wanted to update a light on the MIDI device
at the exact same time the operator pressed a button on said device,
we could get a deadlock. The problem was that MIDIDevice::handle_event()
would lock the MIDIDevice and then go to tell MIDIMapper that the
note was coming (which needs a lock on the MIDIMapper), while in the
other thread, MIDIMapper::refresh_lights() would first lock the MIDIMapper
and then call MIDIDevice::update_lights() with the new set of lights
(which nedes a lock on the MIDIDevice). This is a classic lock ordering
issue.

The solution is to simply make MIDIDevice::handle_event() not lock the
MIDIDevice for anything that calls MIDIMapper; it doesn't actually modify
any state in MIDIDevice, except when we hotplug new devices (and that never
calls MIDIMapper).
shared/midi_device.cpp
shared/midi_device.h