Fix race condition in fluid_player_callback (#783)

Co-authored-by: Arthur Chaloin <arthur.chaloin@gmail.com>
This commit is contained in:
Arthur Chaloin 2021-02-27 13:09:48 +01:00 committed by GitHub
parent 13185d32b2
commit 676923757c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -246,6 +246,7 @@ enum fluid_player_status
{
FLUID_PLAYER_READY, /**< Player is ready */
FLUID_PLAYER_PLAYING, /**< Player is currently playing */
FLUID_PLAYER_STOPPING, /**< Player is stopping, but hasn't finished yet */
FLUID_PLAYER_DONE /**< Player is finished playing */
};

View file

@ -2092,6 +2092,7 @@ fluid_player_callback(void *data, unsigned int msec)
if(fluid_player_get_status(player) != FLUID_PLAYER_PLAYING)
{
fluid_synth_all_notes_off(synth, -1);
fluid_atomic_int_compare_and_exchange(&player->status, FLUID_PLAYER_STOPPING, FLUID_PLAYER_DONE);
return 1;
}
do
@ -2154,7 +2155,7 @@ fluid_player_callback(void *data, unsigned int msec)
}
while(loadnextfile);
fluid_atomic_int_set(&player->status, status);
fluid_atomic_int_compare_and_exchange(&player->status, FLUID_PLAYER_PLAYING, status);
return 1;
}
@ -2193,7 +2194,7 @@ fluid_player_play(fluid_player_t *player)
int
fluid_player_stop(fluid_player_t *player)
{
fluid_atomic_int_set(&player->status, FLUID_PLAYER_DONE);
fluid_atomic_int_set(&player->status, FLUID_PLAYER_STOPPING);
fluid_player_seek(player, fluid_player_get_current_tick(player));
return FLUID_OK;
}