summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-02-03 16:24:03 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-02-03 16:24:03 +0000
commita7b53d41ac1d6d879be0059140d481141d821be3 (patch)
treec45a7e4fafe3d0e658bedc4a8b524b954472d338
parent6b84d000a2e5d8102ad15ace303396a4eeaf29d1 (diff)
more fixes for any and all LV2 UI thread schemes
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@8690 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/lv2_plugin_ui.cc22
-rw-r--r--gtk2_ardour/lv2_plugin_ui.h8
-rw-r--r--libs/pbd/pbd/abstract_ui.cc17
3 files changed, 34 insertions, 13 deletions
diff --git a/gtk2_ardour/lv2_plugin_ui.cc b/gtk2_ardour/lv2_plugin_ui.cc
index de37185198..028f4bec2a 100644
--- a/gtk2_ardour/lv2_plugin_ui.cc
+++ b/gtk2_ardour/lv2_plugin_ui.cc
@@ -42,16 +42,22 @@ LV2PluginUI::lv2_ui_write(LV2UI_Controller controller,
{
LV2PluginUI* me = (LV2PluginUI*)controller;
- cout << "lv2_ui_write, thread registered ? " << me->_thread_registered << endl;
-
- if (!me->_thread_registered && !Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
- cerr << "Registering LV2 external thread " << pthread_self() << endl;
- PBD::notify_gui_about_thread_creation (pthread_self(), me->_lv2->name());
- me->_thread_registered = true;
+ cout << "lv2_ui_write, caller = " << pthread_self() << " current registered UI thread " << me->_current_ui_thread << endl;
+
+ if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
+ if (pthread_self() != me->_current_ui_thread) {
+ if (me->_current_ui_thread != (pthread_t) 0) {
+ cerr << "Unregistering LV2 external thread " << me->_current_ui_thread << endl;
+ PBD::ThreadLeaving (me->_current_ui_thread);
+ }
+ cerr << "Registering new LV2 UI external thread " << pthread_self() << endl;
+ PBD::notify_gui_about_thread_creation (pthread_self(), me->_lv2->name());
+ me->_current_ui_thread = pthread_self();
+ }
}
if (*(float*)buffer != me->_values[port_index]) {
- cout << "set_parameter " << port_index << ":" << *(float*)buffer << endl;
+ // cout << "set_parameter " << port_index << ":" << *(float*)buffer << endl;
me->_lv2->set_parameter(port_index, *(float*)buffer);
}
}
@@ -135,7 +141,7 @@ LV2PluginUI::output_update()
LV2PluginUI::LV2PluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<LV2Plugin> lv2p)
: PlugUIBase (pi)
, _lv2(lv2p)
- , _thread_registered (false)
+ , _current_ui_thread ((pthread_t) 0)
, _inst(NULL)
, _values(NULL)
, _external_ui_ptr(NULL)
diff --git a/gtk2_ardour/lv2_plugin_ui.h b/gtk2_ardour/lv2_plugin_ui.h
index 9400aa6a00..0ad2806537 100644
--- a/gtk2_ardour/lv2_plugin_ui.h
+++ b/gtk2_ardour/lv2_plugin_ui.h
@@ -58,10 +58,10 @@ class LV2PluginUI : public PlugUIBase, public Gtk::VBox
boost::shared_ptr<ARDOUR::LV2Plugin> _lv2;
std::vector<int> _output_ports;
sigc::connection _screen_update_connection;
- bool _thread_registered;
- Gtk::Widget* _gui_widget;
- SLV2UIInstance _inst;
- float* _values;
+ pthread_t _current_ui_thread;
+ Gtk::Widget* _gui_widget;
+ SLV2UIInstance _inst;
+ float* _values;
struct lv2_external_ui_host _external_ui_host;
LV2_Feature _external_ui_feature;
diff --git a/libs/pbd/pbd/abstract_ui.cc b/libs/pbd/pbd/abstract_ui.cc
index bc33fc9a39..6ea8d2b940 100644
--- a/libs/pbd/pbd/abstract_ui.cc
+++ b/libs/pbd/pbd/abstract_ui.cc
@@ -1,4 +1,5 @@
#include <unistd.h>
+#include <cstdlib>
#include <pbd/abstract_ui.h>
#include <pbd/pthread_utils.h>
@@ -30,10 +31,24 @@ AbstractUI<RequestObject>::register_thread (pthread_t thread_id, string name)
template <typename RequestObject> void
AbstractUI<RequestObject>::register_thread_with_request_count (pthread_t thread_id, string thread_name, uint32_t num_requests)
{
+ RequestBuffer* rbuf = static_cast<RequestBuffer*>(pthread_getspecific (thread_request_buffer_key));
+
+ /* we require that the thread being registered is the caller */
+
+ if (thread_id != pthread_self()) {
+ cerr << "thread attempts to register some other thread with the UI named " << name() << endl;
+ abort ();
+ }
+
+ if (rbuf) {
+ /* this thread is already registered with this AbstractUI */
+ return;
+ }
+
RequestBuffer* b = new RequestBuffer (num_requests);
{
- Glib::Mutex::Lock lm (request_buffer_map_lock);
+ Glib::Mutex::Lock lm (request_buffer_map_lock);
request_buffers[thread_id] = b;
}