Taking a readlock after a writelock in the same thread should result
in a deadlock, yet pthread on Linux returns EDEADLK and continues.
glib-2.42.0 ignores EDEADLK and assumes the lock was taken. Releasing
the lock later causes issues: "Calling g_rw_lock_writer_unlock() on a
lock that is not held by the current thread leads to undefined behaviour."
The issue at hand:
AudioStreamView::redisplay_track()
-> foreach_region() #<< WriteLock
-> add_region_view()
...
-> AudioRegionView::create_one_wave()
-> RegionView::update_coverage_frames
-> Playlist::top_unmuted_region_at() #<< ReadLock
All current users of Playlist::foreach_region() are in the GUI
and AFAICT read-only (display regions, update visuals)
in any way that causes problems, just loss of pre-existing connectivity.
1. retain state of current device (and serialize to disk) when switching
devices, and restore that state when switching back to it.
2. fix port and surfacenaming.
3. fix bundle assembly so that all ports (for multi-surface combos) work.
4. rationalize master position numbering
5. add small sleep before starting device handshake after reconnection. This
is ugly but seems to be necessary, unfortunately.
Increased the size of the FIFO that acts as the intermediate between writers and the MidiBuffer. Changed
implementation of ::write() to notice if MidiBuffer::push_back() fails, and then just leave data queued
for subsequent calls to ::flush_output_fifo().
Note: the logic here will be broken by invalid events/data, which ALSO cause MidiBuffer::push_back() to
return false. That needs fixing
1. there's no reason to make the same logic checks in both the Event and 3-arg variants when the Event
version simply calls the 3-arg variant
2. the Event version returned true under all conditions, even if the 3-arg part had failed to push
the Event data into the buffer. It now returns true or false, as intended.
3. remove debug output if a MidiBuffer is full during ::push_back(). The cases where this matters
emit output of their own, or simply remain silent and queue data later