From 0bf4873ab2a905709b7a00a63cea812970c26cda Mon Sep 17 00:00:00 2001 From: derselbst Date: Fri, 25 Aug 2017 21:16:37 +0200 Subject: [PATCH] atomically read queue_stored --- fluidsynth/src/rvoice/fluid_rvoice_event.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fluidsynth/src/rvoice/fluid_rvoice_event.h b/fluidsynth/src/rvoice/fluid_rvoice_event.h index 1432c0c0..e2bde25e 100644 --- a/fluidsynth/src/rvoice/fluid_rvoice_event.h +++ b/fluidsynth/src/rvoice/fluid_rvoice_event.h @@ -67,9 +67,11 @@ int fluid_rvoice_eventhandler_dispatch_count(fluid_rvoice_eventhandler_t*); static FLUID_INLINE void fluid_rvoice_eventhandler_flush(fluid_rvoice_eventhandler_t* handler) { - if (handler->queue_stored > 0) { - fluid_ringbuffer_next_inptr(handler->queue, handler->queue_stored); - handler->queue_stored = 0; + int queue_stored = fluid_atomic_int_get(&handler->queue_stored); + + if (queue_stored > 0) { + fluid_atomic_int_set(&handler->queue_stored, 0); + fluid_ringbuffer_next_inptr(handler->queue, queue_stored); } } @@ -103,11 +105,15 @@ static FLUID_INLINE void fluid_rvoice_eventhandler_add_rvoice(fluid_rvoice_eventhandler_t* handler, fluid_rvoice_t* rvoice) { - if (handler->is_threadsafe) +/* always queue events. without it we may run into timing issues, when events are being dispatched + * via the sampletimers, without actually rendering it. + */ + +// if (handler->is_threadsafe) fluid_rvoice_eventhandler_push_ptr(handler, fluid_rvoice_mixer_add_voice, handler->mixer, rvoice); - else - fluid_rvoice_mixer_add_voice(handler->mixer, rvoice); +// else +// fluid_rvoice_mixer_add_voice(handler->mixer, rvoice); }