[beast: 52/73] BSE: SF2: replace lock/unlock based repo locking with std::lock_guard code
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 52/73] BSE: SF2: replace lock/unlock based repo locking with std::lock_guard code
- Date: Thu, 23 Mar 2017 21:46:03 +0000 (UTC)
commit daf2d587fa9ef80f0cfeb551a9557a311b95681c
Author: Stefan Westerfeld <stefan space twc de>
Date: Mon Dec 5 21:35:11 2016 +0100
BSE: SF2: replace lock/unlock based repo locking with std::lock_guard code
bse/bsesoundfont.cc | 9 +++++----
bse/bsesoundfontosc.cc | 15 ++++++---------
bse/bsesoundfontrepo.cc | 14 ++++++--------
bse/bsesoundfontrepo.hh | 4 ++--
4 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/bse/bsesoundfont.cc b/bse/bsesoundfont.cc
index e9893ba..4296787 100644
--- a/bse/bsesoundfont.cc
+++ b/bse/bsesoundfont.cc
@@ -126,7 +126,8 @@ bse_sound_font_load_blob (BseSoundFont *self,
self->blob = NULL;
}
- fluid_synth_t *fluid_synth = bse_sound_font_repo_lock_fluid_synth (self->sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (self->sfrepo));
+ fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (self->sfrepo);
int sfont_id = fluid_synth_sfload (fluid_synth, bse_storage_blob_file_name (blob), 0);
Bse::Error error;
if (sfont_id != -1)
@@ -156,7 +157,6 @@ bse_sound_font_load_blob (BseSoundFont *self,
bse_storage_blob_unref (blob);
error = Bse::Error::WAVE_NOT_FOUND;
}
- bse_sound_font_repo_unlock_fluid_synth (self->sfrepo);
return error;
}
@@ -167,9 +167,10 @@ bse_sound_font_unload (BseSoundFont *sound_font)
if (sound_font->sfont_id != -1)
{
- fluid_synth_t *fluid_synth = bse_sound_font_repo_lock_fluid_synth (sound_font->sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (sound_font->sfrepo));
+ fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (sound_font->sfrepo);
+
fluid_synth_sfunload (fluid_synth, sound_font->sfont_id, 1 /* reset presets */);
- bse_sound_font_repo_unlock_fluid_synth (sound_font->sfrepo);
}
sound_font->sfont_id = -1;
}
diff --git a/bse/bsesoundfontosc.cc b/bse/bsesoundfontosc.cc
index 4d565b8..6bada07 100644
--- a/bse/bsesoundfontosc.cc
+++ b/bse/bsesoundfontosc.cc
@@ -439,7 +439,8 @@ sound_font_osc_process (BseModule *module,
BseSoundFontRepo *sfrepo = flmod->config.sfrepo;
Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
- fluid_synth_t *fluid_synth = bse_sound_font_repo_lock_fluid_synth (sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (sfrepo));
+ fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (sfrepo);
if (flmod->config.update_preset != flmod->last_update_preset)
{
fluid_synth_program_select (fluid_synth, sfrepo_impl->oscs[flmod->config.osc_id].channel,
@@ -478,8 +479,6 @@ sound_font_osc_process (BseModule *module,
float done = (cstate.n_silence_samples > flmod->config.silence_bound && sfrepo->fluid_events == NULL)
? 1.0 : 0.0;
BSE_MODULE_OSTREAM (module, BSE_SOUND_FONT_OSC_OCHANNEL_DONE_OUT).values = bse_engine_const_values
(done);
}
-
- bse_sound_font_repo_unlock_fluid_synth (sfrepo);
}
static int
@@ -502,7 +501,7 @@ sound_font_osc_process_midi (gpointer null,
BseTrans *trans)
{
SoundFontOscModule *flmod = (SoundFontOscModule *) module->user_data;
- bse_sound_font_repo_lock_fluid_synth (flmod->config.sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (flmod->config.sfrepo));
Bse::SoundFontRepoImpl *sfrepo_impl = flmod->config.sfrepo->as<Bse::SoundFontRepoImpl *>();
int note = bse_note_from_freq (Bse::MusicalTuning::OD_12_TET, event->data.note.frequency);
BseFluidEvent *fluid_event = NULL;
@@ -558,7 +557,6 @@ sound_font_osc_process_midi (gpointer null,
fluid_event->channel = sfrepo_impl->oscs[flmod->config.osc_id].channel;
flmod->config.sfrepo->fluid_events = sfi_ring_insert_sorted (flmod->config.sfrepo->fluid_events,
fluid_event, event_cmp, NULL);
}
- bse_sound_font_repo_unlock_fluid_synth (flmod->config.sfrepo);
}
typedef struct
@@ -635,11 +633,11 @@ bse_sound_font_osc_context_create (BseSource *source,
/* reset fluid synth if necessary */
BseSoundFontOsc *self = BSE_SOUND_FONT_OSC (source);
- fluid_synth_t *fluid_synth = bse_sound_font_repo_lock_fluid_synth (self->config.sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
+ fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (self->config.sfrepo);
if (self->config.sfrepo->n_channel_oscs_active == 0)
fluid_synth_system_reset (fluid_synth);
self->config.sfrepo->n_channel_oscs_active++;
- bse_sound_font_repo_unlock_fluid_synth (self->config.sfrepo);
}
static void
@@ -657,7 +655,7 @@ bse_sound_font_osc_context_dismiss (BseSource *source,
NULL,
module);
/* remove old events from the event queue */
- bse_sound_font_repo_lock_fluid_synth (self->config.sfrepo);
+ std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
SfiRing *fluid_events = self->config.sfrepo->fluid_events;
SfiRing *node = fluid_events;
while (node)
@@ -673,7 +671,6 @@ bse_sound_font_osc_context_dismiss (BseSource *source,
}
self->config.sfrepo->n_channel_oscs_active--;
self->config.sfrepo->fluid_events = fluid_events;
- bse_sound_font_repo_unlock_fluid_synth (self->config.sfrepo);
/* chain parent class' handler */
BSE_SOURCE_CLASS (parent_class)->context_dismiss (source, context_handle, trans);
}
diff --git a/bse/bsesoundfontrepo.cc b/bse/bsesoundfontrepo.cc
index b82dd59..e0e08e8 100644
--- a/bse/bsesoundfontrepo.cc
+++ b/bse/bsesoundfontrepo.cc
@@ -317,19 +317,17 @@ bse_sound_font_repo_list_all_presets (BseSoundFontRepo *sfrepo,
gather_presets (BSE_ITEM (sfrepo), items);
}
-fluid_synth_t *
-bse_sound_font_repo_lock_fluid_synth (BseSoundFontRepo *sfrepo)
+Bse::Mutex&
+bse_sound_font_repo_mutex (BseSoundFontRepo *sfrepo)
{
Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
- sfrepo_impl->fluid_synth_mutex.lock();
- return sfrepo->fluid_synth;
+ return sfrepo_impl->fluid_synth_mutex;
}
-void
-bse_sound_font_repo_unlock_fluid_synth (BseSoundFontRepo *sfrepo)
+fluid_synth_t*
+bse_sound_font_repo_fluid_synth (BseSoundFontRepo *sfrepo)
{
- Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
- sfrepo_impl->fluid_synth_mutex.unlock();
+ return sfrepo->fluid_synth;
}
int
diff --git a/bse/bsesoundfontrepo.hh b/bse/bsesoundfontrepo.hh
index 81613a9..ca3e74c 100644
--- a/bse/bsesoundfontrepo.hh
+++ b/bse/bsesoundfontrepo.hh
@@ -46,8 +46,8 @@ struct BseSoundFontRepoClass : BseSuperClass
/* --- prototypes --- */
void bse_sound_font_repo_list_all_presets (BseSoundFontRepo *sfrepo,
BseIt3mSeq *items);
-fluid_synth_t *bse_sound_font_repo_lock_fluid_synth (BseSoundFontRepo *sfrepo);
-void bse_sound_font_repo_unlock_fluid_synth (BseSoundFontRepo *sfrepo);
+Bse::Mutex& bse_sound_font_repo_mutex (BseSoundFontRepo *sfrepo);
+fluid_synth_t* bse_sound_font_repo_fluid_synth (BseSoundFontRepo *sfrepo);
int bse_sound_font_repo_add_osc (BseSoundFontRepo *sfrepo,
BseSoundFontOsc *osc);
void bse_sound_font_repo_remove_osc (BseSoundFontRepo *sfrepo,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]