From e2ce8e9a5c5a574747db7741626d71652e24b21e Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Tue, 5 Aug 2014 08:19:25 +0200 Subject: gr-fosphor: Prevent multiple thread from initializing fosphor in parallell Although in theory there is nothing wrong with this and fosphor itself should support it. However it seems some OpenCL implementation don't really like having multiple context created in parallell, so we prevent this manually here. Signed-off-by: Sylvain Munaut --- lib/base_sink_c_impl.cc | 14 +++++++++++--- lib/base_sink_c_impl.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/base_sink_c_impl.cc b/lib/base_sink_c_impl.cc index 6d0dcb6..035f6e5 100644 --- a/lib/base_sink_c_impl.cc +++ b/lib/base_sink_c_impl.cc @@ -49,6 +49,8 @@ base_sink_c::base_sink_c(const char *name) } +gr::thread::mutex base_sink_c_impl::s_boot_mutex; + const int base_sink_c_impl::k_db_per_div[] = {1, 2, 5, 10, 20}; @@ -84,9 +86,15 @@ void base_sink_c_impl::worker() this->glctx_init(); /* Init fosphor */ - this->d_fosphor = fosphor_init(); - if (!this->d_fosphor) - return; + { + /* (prevent // init of multiple instance to be gentle on the OpenCL + * implementations that don't like this) */ + gr::thread::scoped_lock guard(s_boot_mutex); + + this->d_fosphor = fosphor_init(); + if (!this->d_fosphor) + return; + } this->settings_apply(~SETTING_DIMENSIONS); diff --git a/lib/base_sink_c_impl.h b/lib/base_sink_c_impl.h index b12764f..fbce636 100644 --- a/lib/base_sink_c_impl.h +++ b/lib/base_sink_c_impl.h @@ -60,6 +60,8 @@ namespace gr { void render(); + static gr::thread::mutex s_boot_mutex; + /* settings refresh logic */ enum { SETTING_DIMENSIONS = (1 << 0), -- cgit v1.2.3