[beast: 4/57] BSE: use std::lock_guard, conditions and std::mutex instead of homegrown primitives
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 4/57] BSE: use std::lock_guard, conditions and std::mutex instead of homegrown primitives
- Date: Sun, 23 Jul 2017 09:58:07 +0000 (UTC)
commit f0712be6c5c02c335355e7b718fd0dc0aeed8888
Author: Tim Janik <timj gnu org>
Date: Tue Jul 4 13:12:58 2017 +0200
BSE: use std::lock_guard, conditions and std::mutex instead of homegrown primitives
Signed-off-by: Tim Janik <timj gnu org>
bse/bseengine.cc | 50 +++++++++++++++++++++++-----------------------
bse/bseenginemaster.cc | 13 ++++++-----
bse/bseenginenode.hh | 8 +++---
bse/bseengineutils.cc | 26 +++++++++++-------------
bse/bsemidireceiver.cc | 2 +-
bse/bsepcmwriter.cc | 4 +-
bse/bsepcmwriter.hh | 2 +-
bse/bsesequencer.cc | 9 +++----
bse/bsesequencer.hh | 8 +++---
bse/bsesoundfont.cc | 4 +-
bse/bsesoundfontosc.cc | 8 +++---
bse/bsesoundfontrepo.cc | 2 +-
bse/bsesoundfontrepo.hh | 4 +-
bse/bsestartup.cc | 10 ++++----
bse/engine-mplan.txt | 4 +-
bse/gslcommon.cc | 12 +++++-----
bse/gsldatacache.cc | 27 +++++++++++++------------
bse/gsldatacache.hh | 2 +-
bse/gslfilehash.cc | 8 +++---
bse/gslfilehash.hh | 2 +-
20 files changed, 102 insertions(+), 103 deletions(-)
---
diff --git a/bse/bseengine.cc b/bse/bseengine.cc
index 359ea34..cc5127b 100644
--- a/bse/bseengine.cc
+++ b/bse/bseengine.cc
@@ -61,7 +61,7 @@ bse_module_new (const BseModuleClass *klass,
node->outputs = ENGINE_NODE_N_OSTREAMS (node) ? sfi_new_struct0 (EngineOutput, ENGINE_NODE_N_OSTREAMS
(node)) : NULL;
node->output_nodes = NULL;
node->integrated = FALSE;
- new (&node->rec_mutex) Bse::Mutex (Bse::RECURSIVE_LOCK);
+ new (&node->rec_mutex) std::recursive_mutex();
for (i = 0; i < ENGINE_NODE_N_OSTREAMS (node); i++)
node->outputs[i].buffer = node->module.ostreams[i].values;
node->flow_jobs = NULL;
@@ -979,10 +979,10 @@ bse_trans_commit (BseTrans *trans)
return exec_tick_stamp;
}
typedef struct {
- BseTrans *trans;
- guint64 tick_stamp;
- Bse::Cond cond;
- Bse::Mutex mutex;
+ BseTrans *trans;
+ guint64 tick_stamp;
+ std::condition_variable cond;
+ std::mutex mutex;
} DTrans;
static gboolean
dtrans_timer (gpointer timer_data,
@@ -1003,7 +1003,7 @@ dtrans_timer (gpointer timer_data,
data->mutex.lock();
data->trans = NULL;
data->mutex.unlock();
- data->cond.signal();
+ data->cond.notify_one();
return FALSE;
}
return TRUE;
@@ -1034,11 +1034,10 @@ bse_trans_commit_delayed (BseTrans *trans,
data.trans = trans;
data.tick_stamp = tick_stamp;
bse_trans_add (wtrans, bse_job_add_timer (dtrans_timer, &data, NULL));
- data.mutex.lock();
+ std::unique_lock<std::mutex> data_lock (data.mutex);
bse_trans_commit (wtrans);
while (data.trans)
- data.cond.wait (data.mutex);
- data.mutex.unlock();
+ data.cond.wait (data_lock);
}
}
@@ -1285,8 +1284,8 @@ bse_engine_configure (guint latency_ms,
guint sample_freq,
guint control_freq)
{
- static Bse::Mutex sync_mutex;
- static Bse::Cond sync_cond;
+ static std::condition_variable sync_cond;
+ static std::mutex sync_mutex;
static gboolean sync_lock = FALSE;
guint block_size, control_raster, success = FALSE;
BseTrans *trans;
@@ -1305,19 +1304,20 @@ bse_engine_configure (guint latency_ms,
return FALSE;
/* block master */
- sync_mutex.lock();
- job = sfi_new_struct0 (BseJob, 1);
- job->job_id = ENGINE_JOB_SYNC;
- job->sync.lock_mutex = &sync_mutex;
- job->sync.lock_cond = &sync_cond;
- job->sync.lock_p = &sync_lock;
- sync_lock = FALSE;
- trans = bse_trans_open();
- bse_trans_add (trans, job);
- bse_trans_commit (trans);
- while (!sync_lock)
- sync_cond.wait (sync_mutex);
- sync_mutex.unlock();
+ {
+ std::unique_lock<std::mutex> sync_guard (sync_mutex);
+ job = sfi_new_struct0 (BseJob, 1);
+ job->job_id = ENGINE_JOB_SYNC;
+ job->sync.lock_mutex = &sync_mutex;
+ job->sync.lock_cond = &sync_cond;
+ job->sync.lock_p = &sync_lock;
+ sync_lock = FALSE;
+ trans = bse_trans_open();
+ bse_trans_add (trans, job);
+ bse_trans_commit (trans);
+ while (!sync_lock)
+ sync_cond.wait (sync_guard);
+ }
if (!_engine_mnl_head())
{
/* cleanup */
@@ -1336,7 +1336,7 @@ bse_engine_configure (guint latency_ms,
/* unblock master */
sync_mutex.lock();
sync_lock = FALSE;
- sync_cond.signal();
+ sync_cond.notify_one();
sync_mutex.unlock();
/* ensure SYNC job got collected */
bse_engine_wait_on_trans();
diff --git a/bse/bseenginemaster.cc b/bse/bseenginemaster.cc
index f0dbdf4..e8e5fd6 100644
--- a/bse/bseenginemaster.cc
+++ b/bse/bseenginemaster.cc
@@ -295,12 +295,13 @@ master_process_job (BseJob *job)
JOB_DEBUG ("sync");
master_need_reflow |= TRUE;
master_schedule_discard();
- job->sync.lock_mutex->lock();
- *job->sync.lock_p = TRUE;
- job->sync.lock_cond->signal();
- while (*job->sync.lock_p)
- job->sync.lock_cond->wait (*job->sync.lock_mutex);
- job->sync.lock_mutex->unlock();
+ {
+ std::unique_lock<std::mutex> sync_guard (*job->sync.lock_mutex);
+ *job->sync.lock_p = TRUE;
+ job->sync.lock_cond->notify_one();
+ while (*job->sync.lock_p)
+ job->sync.lock_cond->wait (sync_guard);
+ }
break;
case ENGINE_JOB_INTEGRATE:
node = job->data.node;
diff --git a/bse/bseenginenode.hh b/bse/bseenginenode.hh
index de3b791..e9e6860 100644
--- a/bse/bseenginenode.hh
+++ b/bse/bseenginenode.hh
@@ -67,9 +67,9 @@ struct _BseJob
gchar *message;
} data;
struct {
- Bse::Mutex *lock_mutex;
- Bse::Cond *lock_cond;
- gboolean *lock_p;
+ std::mutex *lock_mutex;
+ std::condition_variable *lock_cond;
+ gboolean *lock_p;
} sync;
struct {
EngineNode *node;
@@ -164,7 +164,7 @@ typedef struct
struct _EngineNode /* fields sorted by order of processing access */
{
BseModule module;
- Bse::Mutex rec_mutex; /* processing lock */
+ std::recursive_mutex rec_mutex; // processing lock
guint64 counter; /* <= Bse::TickStamp::current() */
EngineInput *inputs; /* [ENGINE_NODE_N_ISTREAMS()] */
EngineJInput **jinputs; /* [ENGINE_NODE_N_JSTREAMS()][jstream->jcount] */
diff --git a/bse/bseengineutils.cc b/bse/bseengineutils.cc
index 1f585bf..5a2e741 100644
--- a/bse/bseengineutils.cc
+++ b/bse/bseengineutils.cc
@@ -112,7 +112,7 @@ bse_engine_free_node (EngineNode *node)
}
klass = node->module.klass;
user_data = node->module.user_data;
- node->rec_mutex.~Mutex();
+ node->rec_mutex.~recursive_mutex();
sfi_delete_struct (EngineNode, node);
/* allow the free function to free the klass as well */
@@ -182,10 +182,10 @@ bse_engine_free_transaction (BseTrans *trans)
/* --- job transactions --- */
-static Bse::Mutex cqueue_trans_mutex;
+static std::mutex cqueue_trans_mutex;
static BseTrans *cqueue_trans_pending_head = NULL;
static BseTrans *cqueue_trans_pending_tail = NULL;
-static Bse::Cond cqueue_trans_cond;
+static std::condition_variable cqueue_trans_cond;
static BseTrans *cqueue_trans_trash_head = NULL;
static BseTrans *cqueue_trans_trash_tail = NULL;
static BseTrans *cqueue_trans_active_head = NULL;
@@ -211,17 +211,16 @@ _engine_enqueue_trans (BseTrans *trans)
cqueue_trans_pending_tail = trans;
guint64 base_stamp = cqueue_commit_base_stamp;
cqueue_trans_mutex.unlock();
- cqueue_trans_cond.broadcast();
+ cqueue_trans_cond.notify_all();
return base_stamp + bse_engine_block_size(); /* returns tick_stamp of when this transaction takes effect
*/
}
void
_engine_wait_on_trans (void)
{
- cqueue_trans_mutex.lock();
+ std::unique_lock<std::mutex> cqueue_trans_guard (cqueue_trans_mutex);
while (cqueue_trans_pending_head || cqueue_trans_active_head)
- cqueue_trans_cond.wait (cqueue_trans_mutex);
- cqueue_trans_mutex.unlock();
+ cqueue_trans_cond.wait (cqueue_trans_guard);
}
gboolean
@@ -302,7 +301,7 @@ _engine_pop_job (gboolean update_commit_stamp)
if (!cqueue_trans_job && update_commit_stamp)
cqueue_commit_base_stamp = Bse::TickStamp::current(); /* last job has been handed out */
cqueue_trans_mutex.unlock();
- cqueue_trans_cond.broadcast();
+ cqueue_trans_cond.notify_all();
}
else /* not currently processing a transaction */
{
@@ -391,11 +390,11 @@ bse_engine_has_garbage (void)
/* --- node processing queue --- */
-static Bse::Mutex pqueue_mutex;
+static std::mutex pqueue_mutex;
static EngineSchedule *pqueue_schedule = NULL;
static guint pqueue_n_nodes = 0;
static guint pqueue_n_cycles = 0;
-static Bse::Cond pqueue_done_cond;
+static std::condition_variable pqueue_done_cond;
static EngineTimedJob *pqueue_trash_tjobs_head = NULL;
static EngineTimedJob *pqueue_trash_tjobs_tail = NULL;
@@ -518,7 +517,7 @@ _engine_push_processed_node (EngineNode *node)
pqueue_n_nodes -= 1;
ENGINE_NODE_UNLOCK (node);
if (!pqueue_n_nodes && !pqueue_n_cycles && BSE_ENGINE_SCHEDULE_NONPOPABLE (pqueue_schedule))
- pqueue_done_cond.signal();
+ pqueue_done_cond.notify_one();
pqueue_mutex.unlock();
}
@@ -539,10 +538,9 @@ _engine_push_processed_cycle (SfiRing *cycle)
void
_engine_wait_on_unprocessed (void)
{
- pqueue_mutex.lock();
+ std::unique_lock<std::mutex> pqueue_guard (pqueue_mutex);
while (pqueue_n_nodes || pqueue_n_cycles || !BSE_ENGINE_SCHEDULE_NONPOPABLE (pqueue_schedule))
- pqueue_done_cond.wait (pqueue_mutex);
- pqueue_mutex.unlock();
+ pqueue_done_cond.wait (pqueue_guard);
}
diff --git a/bse/bsemidireceiver.cc b/bse/bsemidireceiver.cc
index 02577c2..87b3f7d 100644
--- a/bse/bsemidireceiver.cc
+++ b/bse/bsemidireceiver.cc
@@ -20,7 +20,7 @@ using namespace std;
#define VDUMP(...) Bse::dump ("midi-voice", __VA_ARGS__)
/* --- variables --- */
-static Bse::Mutex global_midi_mutex;
+static std::mutex global_midi_mutex;
#define BSE_MIDI_RECEIVER_LOCK() global_midi_mutex.lock()
#define BSE_MIDI_RECEIVER_UNLOCK() global_midi_mutex.unlock()
diff --git a/bse/bsepcmwriter.cc b/bse/bsepcmwriter.cc
index fbc9d24..c9f6740 100644
--- a/bse/bsepcmwriter.cc
+++ b/bse/bsepcmwriter.cc
@@ -48,7 +48,7 @@ bse_pcm_writer_class_init (BsePcmWriterClass *klass)
static void
bse_pcm_writer_init (BsePcmWriter *self)
{
- new (&self->mutex) Bse::Mutex();
+ new (&self->mutex) std::mutex();
}
static void
@@ -62,7 +62,7 @@ bse_pcm_writer_finalize (GObject *object)
}
/* chain parent class' handler */
G_OBJECT_CLASS (parent_class)->finalize (object);
- self->mutex.~Mutex();
+ self->mutex.~mutex();
}
Bse::Error
diff --git a/bse/bsepcmwriter.hh b/bse/bsepcmwriter.hh
index 70f8b06..25f8c2a 100644
--- a/bse/bsepcmwriter.hh
+++ b/bse/bsepcmwriter.hh
@@ -15,7 +15,7 @@
/* --- BsePcmWriter --- */
struct BsePcmWriter : BseItem {
- Bse::Mutex mutex;
+ std::mutex mutex;
guint open : 1;
guint broken : 1;
gint fd;
diff --git a/bse/bsesequencer.cc b/bse/bsesequencer.cc
index 5c8b55c..6152f26 100644
--- a/bse/bsesequencer.cc
+++ b/bse/bsesequencer.cc
@@ -26,7 +26,7 @@ namespace Bse {
using Rapicorn::ThreadInfo; // FIXME
Sequencer *Sequencer::singleton_ = NULL;
-Mutex Sequencer::sequencer_mutex_;
+std::mutex Sequencer::sequencer_mutex_;
static ThreadInfo *sequencer_thread_self = NULL;
class Sequencer::PollPool {
@@ -161,7 +161,7 @@ Sequencer::remove_io_watch (BseIOWatch watch_func, void *watch_data)
* least conceptually) or has never been installed
*/
bool removal_success;
- BSE_SEQUENCER_LOCK();
+ std::unique_lock<std::mutex> sequencer_guard (sequencer_mutex_);
if (current_watch_func == watch_func && current_watch_data == watch_data)
{ /* watch_func() to be removed is currently in call */
if (&ThreadInfo::self() == sequencer_thread_self)
@@ -177,7 +177,7 @@ Sequencer::remove_io_watch (BseIOWatch watch_func, void *watch_data)
current_watch_needs_remove2 = true;
/* wait until watch_func() call has finished */
while (current_watch_func == watch_func && current_watch_data == watch_data)
- watch_cond_.wait (sequencer_mutex_);
+ watch_cond_.wait (sequencer_guard);
}
}
else /* can remove (watch_func(watch_data) not in call) */
@@ -186,7 +186,6 @@ Sequencer::remove_io_watch (BseIOWatch watch_func, void *watch_data)
/* wake up sequencer thread, so it stops polling on fds it doesn't own anymore */
wakeup();
}
- BSE_SEQUENCER_UNLOCK();
if (!removal_success)
Bse::warning ("%s: failed to remove %p(%p)", __func__, watch_func, watch_data);
}
@@ -229,7 +228,7 @@ Sequencer::pool_poll_Lm (gint timeout_ms)
current_watch_needs_remove2 = false;
current_watch_func = NULL;
current_watch_data = NULL;
- watch_cond_.broadcast(); // wake up threads in remove_io_watch()
+ watch_cond_.notify_all(); // wake up threads in remove_io_watch()
}
}
return true;
diff --git a/bse/bsesequencer.hh b/bse/bsesequencer.hh
index f32bc30..6ece7f5 100644
--- a/bse/bsesequencer.hh
+++ b/bse/bsesequencer.hh
@@ -10,11 +10,11 @@ namespace Bse {
*/
class Sequencer {
static Sequencer *singleton_;
- static Mutex sequencer_mutex_;
+ static std::mutex sequencer_mutex_;
struct PollPool;
uint64 stamp_; // sequencer time (ahead of real time)
SfiRing *songs_;
- Cond watch_cond_;
+ std::condition_variable watch_cond_;
PollPool *poll_pool_;
EventFd event_fd_;
std::thread thread_;
@@ -40,8 +40,8 @@ public:
void remove_song (BseSong *song);
bool thread_lagging (uint n_blocks);
void wakeup () { event_fd_.wakeup(); }
- static Mutex& sequencer_mutex () { return sequencer_mutex_; }
- static Sequencer& instance () { return *singleton_; }
+ static std::mutex& sequencer_mutex () { return sequencer_mutex_; }
+ static Sequencer& instance () { return *singleton_; }
};
#define BSE_SEQUENCER_LOCK() (Bse::Sequencer::sequencer_mutex().lock())
diff --git a/bse/bsesoundfont.cc b/bse/bsesoundfont.cc
index 27e1649..50695de 100644
--- a/bse/bsesoundfont.cc
+++ b/bse/bsesoundfont.cc
@@ -127,7 +127,7 @@ bse_sound_font_load_blob (BseSoundFont *self,
assert_return (sound_font_impl->sfrepo != NULL, Bse::Error::INTERNAL);
assert_return (sound_font_impl->sfont_id == -1, Bse::Error::INTERNAL);
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (sound_font_impl->sfrepo));
+ std::lock_guard<std::mutex> guard (bse_sound_font_repo_mutex (sound_font_impl->sfrepo));
fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (sound_font_impl->sfrepo);
int sfont_id = fluid_synth_sfload (fluid_synth, use_searchpath (blob->file_name()).c_str(), 0);
Bse::Error error;
@@ -170,7 +170,7 @@ bse_sound_font_unload (BseSoundFont *sound_font)
if (sound_font_impl->sfont_id != -1)
{
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (sound_font_impl->sfrepo));
+ std::lock_guard<std::mutex> guard (bse_sound_font_repo_mutex (sound_font_impl->sfrepo));
fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (sound_font_impl->sfrepo);
fluid_synth_sfunload (fluid_synth, sound_font_impl->sfont_id, 1 /* reset presets */);
diff --git a/bse/bsesoundfontosc.cc b/bse/bsesoundfontosc.cc
index 2c5ffa8..c592809 100644
--- a/bse/bsesoundfontosc.cc
+++ b/bse/bsesoundfontosc.cc
@@ -439,7 +439,7 @@ sound_font_osc_process (BseModule *module,
BseSoundFontRepo *sfrepo = flmod->config.sfrepo;
Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (sfrepo));
+ std::lock_guard<std::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)
{
@@ -501,7 +501,7 @@ sound_font_osc_process_midi (gpointer null,
BseTrans *trans)
{
SoundFontOscModule *flmod = (SoundFontOscModule *) module->user_data;
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (flmod->config.sfrepo));
+ std::lock_guard<std::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;
@@ -633,7 +633,7 @@ bse_sound_font_osc_context_create (BseSource *source,
/* reset fluid synth if necessary */
BseSoundFontOsc *self = BSE_SOUND_FONT_OSC (source);
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
+ std::lock_guard<std::mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
fluid_synth_t *fluid_synth = bse_sound_font_repo_fluid_synth (self->config.sfrepo);
Bse::SoundFontRepoImpl *sfrepo_impl = self->config.sfrepo->as<Bse::SoundFontRepoImpl *>();
if (sfrepo_impl->n_channel_oscs_active == 0)
@@ -656,7 +656,7 @@ bse_sound_font_osc_context_dismiss (BseSource *source,
NULL,
module);
/* remove old events from the event queue */
- std::lock_guard<Bse::Mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
+ std::lock_guard<std::mutex> guard (bse_sound_font_repo_mutex (self->config.sfrepo));
SfiRing *fluid_events = sfrepo_impl->fluid_events;
SfiRing *node = fluid_events;
while (node)
diff --git a/bse/bsesoundfontrepo.cc b/bse/bsesoundfontrepo.cc
index b8b510c..f008087 100644
--- a/bse/bsesoundfontrepo.cc
+++ b/bse/bsesoundfontrepo.cc
@@ -289,7 +289,7 @@ bse_sound_font_repo_list_all_presets (BseSoundFontRepo *sfrepo,
gather_presets (BSE_ITEM (sfrepo), items);
}
-Bse::Mutex&
+std::mutex&
bse_sound_font_repo_mutex (BseSoundFontRepo *sfrepo)
{
Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
diff --git a/bse/bsesoundfontrepo.hh b/bse/bsesoundfontrepo.hh
index 6161ade..6ab0fb3 100644
--- a/bse/bsesoundfontrepo.hh
+++ b/bse/bsesoundfontrepo.hh
@@ -35,7 +35,7 @@ struct BseSoundFontRepoClass : BseSuperClass
/* --- prototypes --- */
void bse_sound_font_repo_list_all_presets (BseSoundFontRepo *sfrepo,
BseIt3mSeq *items);
-Bse::Mutex& bse_sound_font_repo_mutex (BseSoundFontRepo *sfrepo);
+std::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);
@@ -46,7 +46,7 @@ namespace Bse {
class SoundFontRepoImpl : public SuperImpl, public virtual SoundFontRepoIface {
public:
- Bse::Mutex fluid_synth_mutex;
+ std::mutex fluid_synth_mutex;
struct ChannelState {
std::vector<float> values_left;
std::vector<float> values_right;
diff --git a/bse/bsestartup.cc b/bse/bsestartup.cc
index c166fb4..d5ae5c0 100644
--- a/bse/bsestartup.cc
+++ b/bse/bsestartup.cc
@@ -37,7 +37,7 @@ init_needed ()
}
// == TaskRegistry ==
-static Bse::Mutex task_registry_mutex_;
+static std::mutex task_registry_mutex_;
static TaskRegistry::List task_registry_tasks_;
void
@@ -46,14 +46,14 @@ TaskRegistry::add (const std::string &name, int pid, int tid)
Rapicorn::TaskStatus task (pid, tid);
task.name = name;
task.update();
- Bse::ScopedLock<Bse::Mutex> locker (task_registry_mutex_);
+ std::lock_guard<std::mutex> locker (task_registry_mutex_);
task_registry_tasks_.push_back (task);
}
bool
TaskRegistry::remove (int tid)
{
- Bse::ScopedLock<Bse::Mutex> locker (task_registry_mutex_);
+ std::lock_guard<std::mutex> locker (task_registry_mutex_);
for (auto it = task_registry_tasks_.begin(); it != task_registry_tasks_.end(); it++)
if (it->task_id == tid)
{
@@ -66,7 +66,7 @@ TaskRegistry::remove (int tid)
void
TaskRegistry::update ()
{
- Bse::ScopedLock<Bse::Mutex> locker (task_registry_mutex_);
+ std::lock_guard<std::mutex> locker (task_registry_mutex_);
for (auto &task : task_registry_tasks_)
task.update();
}
@@ -74,7 +74,7 @@ TaskRegistry::update ()
TaskRegistry::List
TaskRegistry::list ()
{
- Bse::ScopedLock<Bse::Mutex> locker (task_registry_mutex_);
+ std::lock_guard<std::mutex> locker (task_registry_mutex_);
return task_registry_tasks_;
}
diff --git a/bse/engine-mplan.txt b/bse/engine-mplan.txt
index 807fbc9..6ff4d74 100644
--- a/bse/engine-mplan.txt
+++ b/bse/engine-mplan.txt
@@ -210,7 +210,7 @@ Thread types:
at a time.
i.e. if more than one user thread need to call engine API
functions, the user has to take measures to avoid concurrency
- in calling these functions, e.g. by using a SfiMutex which is
+ in calling these functions, e.g. by using a mutex which is
to be locked around engine API calls.
* MasterThread; the engine, if configured accordingly,
sets up one master thread which
@@ -283,4 +283,4 @@ May 05 2001 Tim Janik
* initial writeup
LocalWords: BSE API BseModule EngineNode istreams ostreams A's B's sync
-LocalWords: bseengine SfiMutex UserThread MasterThread SlaveThread SlaveThreads
+LocalWords: bseengine UserThread MasterThread SlaveThread SlaveThreads
diff --git a/bse/gslcommon.cc b/bse/gslcommon.cc
index f1f2b2c..dc50ba4 100644
--- a/bse/gslcommon.cc
+++ b/bse/gslcommon.cc
@@ -16,7 +16,7 @@
namespace Bse {
// == TickStamp ==
-static Bse::Mutex global_tick_stamp_mutex;
+static std::mutex global_tick_stamp_mutex;
static uint64 tick_stamp_system_time = 0;
static uint64 tick_stamp_leaps = 0;
std::atomic<uint64> TickStamp::global_tick_stamp { 0 }; // initialized to 1 from gsl_init(), so
0 == invalid
@@ -32,7 +32,7 @@ TickStamp::_init_forgsl()
void
TickStamp::_set_leap (uint64 ticks)
{
- Bse::ScopedLock<Bse::Mutex> locker (global_tick_stamp_mutex);
+ std::lock_guard<std::mutex> locker (global_tick_stamp_mutex);
tick_stamp_leaps = ticks;
}
@@ -45,7 +45,7 @@ TickStamp::_increment ()
systime = sfi_time_system ();
newstamp = global_tick_stamp + tick_stamp_leaps;
{
- Bse::ScopedLock<Bse::Mutex> locker (global_tick_stamp_mutex);
+ std::lock_guard<std::mutex> locker (global_tick_stamp_mutex);
global_tick_stamp = newstamp;
tick_stamp_system_time = systime;
}
@@ -85,7 +85,7 @@ TickStamp::Update
TickStamp::get_last()
{
Update ustamp;
- Bse::ScopedLock<Bse::Mutex> locker (global_tick_stamp_mutex);
+ std::lock_guard<std::mutex> locker (global_tick_stamp_mutex);
ustamp.tick_stamp = global_tick_stamp;
ustamp.system_time = tick_stamp_system_time;
return ustamp;
@@ -115,7 +115,7 @@ TickStamp::create_wakeup (const std::function<void()> &wakeup)
void
TickStamp::Wakeup::awake_after (uint64 stamp)
{
- Bse::ScopedLock<Bse::Mutex> locker (global_tick_stamp_mutex);
+ std::lock_guard<std::mutex> locker (global_tick_stamp_mutex);
if (!awake_stamp_ && stamp)
{
tick_stamp_wakeups.push_back (shared_from_this());
@@ -151,7 +151,7 @@ TickStamp::Wakeup::awake_before (uint64 stamp)
void
TickStamp::Wakeup::_emit_wakeups (uint64 wakeup_stamp)
{
- Bse::ScopedLock<Bse::Mutex> locker (global_tick_stamp_mutex);
+ std::lock_guard<std::mutex> locker (global_tick_stamp_mutex);
std::list<TickStampWakeupP> list, notifies;
list.swap (tick_stamp_wakeups);
for (auto it : list)
diff --git a/bse/gsldatacache.cc b/bse/gsldatacache.cc
index 997fc9e..f95feab 100644
--- a/bse/gsldatacache.cc
+++ b/bse/gsldatacache.cc
@@ -42,12 +42,14 @@ static GslDataCacheNode* data_cache_new_node_L (GslDataCache *dcache,
int64 offset,
guint pos,
gboolean demand_load);
+
/* --- variables --- */
-static Bse::Spinlock global_dcache_spinlock;
-static Bse::Cond global_dcache_cond_node_filled;
-static SfiRing *global_dcache_list = NULL;
-static guint global_dcache_count = 0;
-static guint global_dcache_n_aged_nodes = 0;
+static Bse::Spinlock global_dcache_spinlock;
+static std::condition_variable global_dcache_cond_node_filled;
+static SfiRing *global_dcache_list = NULL;
+static guint global_dcache_count = 0;
+static guint global_dcache_n_aged_nodes = 0;
+
/* --- functions --- */
void
_gsl_init_data_caches (void)
@@ -70,7 +72,7 @@ gsl_data_cache_new (GslDataHandle *dhandle,
assert_return (padding < node_size / 2, NULL);
/* allocate new closed dcache if necessary */
dcache = sfi_new_struct (GslDataCache, 1);
- new (&dcache->mutex) Bse::Mutex();
+ new (&dcache->mutex) std::mutex();
dcache->dhandle = gsl_data_handle_ref (dhandle);
dcache->open_count = 0;
dcache->ref_count = 1;
@@ -158,7 +160,7 @@ dcache_free (GslDataCache *dcache)
sfi_delete_struct (GslDataCacheNode, node);
}
g_free (dcache->nodes);
- dcache->mutex.~Mutex();
+ dcache->mutex.~mutex();
sfi_delete_struct (GslDataCache, dcache);
}
void
@@ -329,7 +331,7 @@ data_cache_new_node_L (GslDataCache *dcache,
memset (data, 0, size * sizeof (data[0]));
dcache->mutex.lock();
dnode->data = node_data;
- global_dcache_cond_node_filled.broadcast();
+ global_dcache_cond_node_filled.notify_all();
return dnode;
}
GslDataCacheNode*
@@ -343,7 +345,7 @@ gsl_data_cache_ref_node (GslDataCache *dcache,
assert_return (dcache->ref_count > 0, NULL);
assert_return (dcache->open_count > 0, NULL);
assert_return (offset < gsl_data_handle_length (dcache->dhandle), NULL);
- dcache->mutex.lock();
+ std::unique_lock<std::mutex> dcache_lock (dcache->mutex);
node_p = data_cache_lookup_nextmost_node_L (dcache, offset);
if (node_p)
{
@@ -358,7 +360,7 @@ gsl_data_cache_ref_node (GslDataCache *dcache,
node->ref_count++;
else
node = NULL;
- dcache->mutex.unlock();
+ dcache_lock.unlock();
if (node && rejuvenate_node)
{
global_dcache_spinlock.lock(); /* different lock */
@@ -370,8 +372,8 @@ gsl_data_cache_ref_node (GslDataCache *dcache,
node->ref_count++;
if (load_request == GSL_DATA_CACHE_DEMAND_LOAD)
while (!node->data)
- global_dcache_cond_node_filled.wait (dcache->mutex);
- dcache->mutex.unlock();
+ global_dcache_cond_node_filled.wait (dcache_lock);
+ dcache_lock.unlock();
/* printerr ("hit: %d :%d: %d\n", node->offset, offset, node->offset + dcache->node_size); */
if (rejuvenate_node)
{
@@ -392,7 +394,6 @@ gsl_data_cache_ref_node (GslDataCache *dcache,
node = data_cache_new_node_L (dcache, offset, insertion_pos, load_request == GSL_DATA_CACHE_DEMAND_LOAD);
else
node = NULL;
- dcache->mutex.unlock();
return node;
}
static gboolean /* still locked */
diff --git a/bse/gsldatacache.hh b/bse/gsldatacache.hh
index 73262db..18b22ab 100644
--- a/bse/gsldatacache.hh
+++ b/bse/gsldatacache.hh
@@ -15,7 +15,7 @@ struct _GslDataCache
{
GslDataHandle *dhandle;
guint open_count;
- Bse::Mutex mutex;
+ std::mutex mutex;
guint ref_count;
guint node_size; /* power of 2, const for all dcaches */
guint padding; /* n_values around blocks */
diff --git a/bse/gslfilehash.cc b/bse/gslfilehash.cc
index 8995cbd..9b82e8d 100644
--- a/bse/gslfilehash.cc
+++ b/bse/gslfilehash.cc
@@ -13,8 +13,8 @@
#define HASH_LONG(l) (l)
#endif
/* --- variables --- */
-static Bse::Mutex fdpool_mutex;
-static GHashTable *hfile_ht = NULL;
+static std::mutex fdpool_mutex;
+static GHashTable *hfile_ht = NULL;
/* --- functions --- */
static guint
hfile_hash (gconstpointer key)
@@ -96,7 +96,7 @@ gsl_hfile_open (const gchar *file_name)
if (fd >= 0)
{
hfile = sfi_new_struct0 (GslHFile, 1);
- new (&hfile->mutex) Bse::Mutex();
+ new (&hfile->mutex) std::mutex();
hfile->file_name = g_strdup (file_name);
hfile->mtime = key.mtime;
hfile->n_bytes = key.n_bytes;
@@ -146,7 +146,7 @@ gsl_hfile_close (GslHFile *hfile)
{
close (hfile->fd);
g_free (hfile->file_name);
- hfile->mutex.~Mutex();
+ hfile->mutex.~mutex();
sfi_delete_struct (GslHFile, hfile);
}
errno = 0;
diff --git a/bse/gslfilehash.hh b/bse/gslfilehash.hh
index c187e12..17952c8 100644
--- a/bse/gslfilehash.hh
+++ b/bse/gslfilehash.hh
@@ -14,7 +14,7 @@ typedef struct {
GslLong n_bytes;
/*< private >*/
GslLong cpos;
- Bse::Mutex mutex;
+ std::mutex mutex;
gint fd;
guint ocount;
GslLong zoffset;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]