Fix #9117, 04ce1f07: [Fluidsynth] Infinite wait when stopping song #9181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
FluidSynth 2.2.0 hangs when stopping a song.
Description
In FluidSynth 2.2.0 an extra state was added to denote stopping. To transition from this state to a stopped state the rendering needs to be running. Since 04ce1f0 locking was added that skipped the rendering when something else held a lock, so the state would never get to stopped and join would never return.
Now the join will be performed while the lock is not held, so the other thread can transition the state. After that, the lock is regained and the rest of the cleanup is performed.
Limitations
Does not solve the issue when the audio driver does not have its own thread (e.g. Allegro). Don't have a good idea how to solve that nicely at the moment either. Maybe forcing all audio drivers to use a thread? I'll leave that issue to some other PR, however this closes #9117.
I have no idea why thetry_lock
was used in the sound rendering, so I have no idea what the repercussions of this change are. It seems to work for me. Since nielsmh added that, I've requested him to take a look at it.Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.