diff options
author | Carl Hetherington <carl@carlh.net> | 2011-10-28 17:04:09 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-10-28 17:04:09 +0000 |
commit | 7bdcc127e3e42bd76b997b56ecd938b1127d790b (patch) | |
tree | f1e9856094ee5a54cc28957508f2b693fbcd043a /gtk2_ardour | |
parent | f65e3f287b48fef6d4fdb8c4456c0eada4c4431c (diff) |
Use shared_ptr for Port in the AudioEngine; improves thread-safety of the audio engine's port list as a writer cannot destroy a port in one thread while the port list is being iterated in another.
git-svn-id: svn://localhost/ardour2/branches/3.0@10327 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/export_channel_selector.cc | 35 | ||||
-rw-r--r-- | gtk2_ardour/export_channel_selector.h | 12 | ||||
-rw-r--r-- | gtk2_ardour/global_port_matrix.cc | 8 | ||||
-rw-r--r-- | gtk2_ardour/io_selector.cc | 4 | ||||
-rw-r--r-- | gtk2_ardour/mixer_strip.cc | 11 | ||||
-rw-r--r-- | gtk2_ardour/mixer_strip.h | 2 | ||||
-rw-r--r-- | gtk2_ardour/port_matrix.cc | 2 |
7 files changed, 41 insertions, 33 deletions
diff --git a/gtk2_ardour/export_channel_selector.cc b/gtk2_ardour/export_channel_selector.cc index 7f83858d99..6cf73d2296 100644 --- a/gtk2_ardour/export_channel_selector.cc +++ b/gtk2_ardour/export_channel_selector.cc @@ -218,21 +218,21 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c) } Glib::RefPtr<Gtk::ListStore> port_list = r_it->get_value (route_cols.port_list_col); - std::set<AudioPort *> route_ports; - std::set<AudioPort *> intersection; - std::map<AudioPort *, string> port_labels; + std::set<boost::weak_ptr<AudioPort> > route_ports; + std::set<boost::weak_ptr<AudioPort> > intersection; + std::map<boost::weak_ptr<AudioPort>, string> port_labels; for (Gtk::ListStore::Children::const_iterator p_it = port_list->children().begin(); p_it != port_list->children().end(); ++p_it) { route_ports.insert ((*p_it)->get_value (route_cols.port_cols.port)); - port_labels.insert (std::pair<AudioPort*, string> ((*p_it)->get_value (route_cols.port_cols.port), - (*p_it)->get_value (route_cols.port_cols.label))); + port_labels.insert (make_pair ((*p_it)->get_value (route_cols.port_cols.port), + (*p_it)->get_value (route_cols.port_cols.label))); } std::set_intersection (pec->get_ports().begin(), pec->get_ports().end(), route_ports.begin(), route_ports.end(), - std::insert_iterator<std::set<AudioPort *> > (intersection, intersection.begin())); + std::insert_iterator<std::set<boost::weak_ptr<AudioPort> > > (intersection, intersection.begin())); - intersection.erase (0); // Remove "none" selection + intersection.erase (boost::weak_ptr<AudioPort> ()); // Remove "none" selection if (intersection.empty()) { continue; @@ -244,13 +244,13 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c) /* Set previous channels (if any) to none */ for (uint32_t chn = 1; chn < i; ++chn) { - r_it->set_value (route_cols.get_channel (chn).port, (AudioPort *) 0); + r_it->set_value (route_cols.get_channel (chn).port, boost::weak_ptr<AudioPort> ()); r_it->set_value (route_cols.get_channel (chn).label, string ("(none)")); } } - AudioPort * port = *intersection.begin(); - std::map<AudioPort *, string>::iterator label_it = port_labels.find (port); + boost::weak_ptr<AudioPort> port = *intersection.begin(); + std::map<boost::weak_ptr<AudioPort>, string>::iterator label_it = port_labels.find (port); string label = label_it != port_labels.end() ? label_it->second : "error"; r_it->set_value (route_cols.get_channel (i).port, port); @@ -294,7 +294,7 @@ PortExportChannelSelector::ChannelTreeView::add_route (ARDOUR::IO * io) row = *iter; row[route_cols.port_cols.selected] = false; - row[route_cols.port_cols.port] = 0; + row[route_cols.port_cols.port] = boost::weak_ptr<AudioPort> (); row[route_cols.port_cols.label] = "(none)"; } @@ -331,7 +331,7 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) { std::string label = it->get_value(route_cols.selected) ? "(none)" : ""; it->set_value (route_cols.get_channel (n_channels).label, label); - it->set_value (route_cols.get_channel (n_channels).port, (AudioPort *) 0); + it->set_value (route_cols.get_channel (n_channels).port, boost::weak_ptr<AudioPort> ()); } /* set column width */ @@ -355,7 +355,6 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels void PortExportChannelSelector::ChannelTreeView::update_config () { - if (!config) { return; } config->clear_channels(); @@ -372,7 +371,8 @@ PortExportChannelSelector::ChannelTreeView::update_config () continue; } - AudioPort * port = row[route_cols.get_channel (i).port]; + boost::weak_ptr<AudioPort> weak_port = row[route_cols.get_channel (i).port]; + boost::shared_ptr<AudioPort> port = weak_port.lock (); if (port) { pec->add_port (port); } @@ -398,7 +398,7 @@ PortExportChannelSelector::ChannelTreeView::update_toggle_selection (std::string } iter->set_value (route_cols.get_channel (i).label, std::string("(none)")); - iter->set_value (route_cols.get_channel (i).port, (AudioPort *) 0); + iter->set_value (route_cols.get_channel (i).port, boost::weak_ptr<AudioPort> ()); Glib::RefPtr<Gtk::ListStore> port_list = iter->get_value (route_cols.port_list_col); Gtk::ListStore::Children::iterator port_it; @@ -407,7 +407,7 @@ PortExportChannelSelector::ChannelTreeView::update_toggle_selection (std::string for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) { if (port_number == i) { iter->set_value (route_cols.get_channel (i).label, (std::string) (*port_it)->get_value (route_cols.port_cols.label)); - iter->set_value (route_cols.get_channel (i).port, (AudioPort *) (*port_it)->get_value (route_cols.port_cols.port)); + iter->set_value (route_cols.get_channel (i).port, (*port_it)->get_value (route_cols.port_cols.port)); } ++port_number; @@ -429,7 +429,8 @@ PortExportChannelSelector::ChannelTreeView::update_selection_text (std::string c for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) { std::string label = port_it->get_value (route_cols.port_cols.label); if (label == new_text) { - iter->set_value (route_cols.get_channel (channel).port, (AudioPort *) (*port_it)[route_cols.port_cols.port]); + boost::weak_ptr<AudioPort> w = (*port_it)[route_cols.port_cols.port]; + iter->set_value (route_cols.get_channel (channel).port, w); } } diff --git a/gtk2_ardour/export_channel_selector.h b/gtk2_ardour/export_channel_selector.h index dda449d931..511ccd5b78 100644 --- a/gtk2_ardour/export_channel_selector.h +++ b/gtk2_ardour/export_channel_selector.h @@ -129,8 +129,8 @@ class PortExportChannelSelector : public ExportChannelSelector public: Channel (RouteCols & cols) { cols.add (port); cols.add (label); } - Gtk::TreeModelColumn<ARDOUR::AudioPort *> port; - Gtk::TreeModelColumn<std::string> label; + Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port; + Gtk::TreeModelColumn<std::string> label; }; std::list<Channel> channels; @@ -144,11 +144,11 @@ class PortExportChannelSelector : public ExportChannelSelector class PortCols : public Gtk::TreeModel::ColumnRecord { public: - PortCols () { add (selected); add(port); add(label); } + PortCols () { add(selected); add(port); add(label); } - Gtk::TreeModelColumn<bool> selected; // not used ATM - Gtk::TreeModelColumn<ARDOUR::AudioPort *> port; - Gtk::TreeModelColumn<std::string> label; + Gtk::TreeModelColumn<bool> selected; // not used ATM + Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port; + Gtk::TreeModelColumn<std::string> label; }; PortCols port_cols; }; diff --git a/gtk2_ardour/global_port_matrix.cc b/gtk2_ardour/global_port_matrix.cc index 565def896e..5e5218bda8 100644 --- a/gtk2_ardour/global_port_matrix.cc +++ b/gtk2_ardour/global_port_matrix.cc @@ -56,8 +56,8 @@ GlobalPortMatrix::set_state (BundleChannel c[2], bool s) for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) { for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) { - Port* p = _session->engine().get_port_by_name (*i); - Port* q = _session->engine().get_port_by_name (*j); + boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i); + boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j); if (p) { if (s) { @@ -105,8 +105,8 @@ GlobalPortMatrix::get_state (BundleChannel c[2]) const for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) { for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) { - Port* p = _session->engine().get_port_by_name (*i); - Port* q = _session->engine().get_port_by_name (*j); + boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i); + boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j); if (!p && !q) { /* two non-Ardour ports; things are slightly more involved */ diff --git a/gtk2_ardour/io_selector.cc b/gtk2_ardour/io_selector.cc index b9e19de7ad..fea21ced0f 100644 --- a/gtk2_ardour/io_selector.cc +++ b/gtk2_ardour/io_selector.cc @@ -139,7 +139,7 @@ IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s) for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) { for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) { - Port* f = _session->engine().get_port_by_name (*i); + boost::shared_ptr<Port> f = _session->engine().get_port_by_name (*i); if (!f) { return; } @@ -172,7 +172,7 @@ IOSelector::get_state (ARDOUR::BundleChannel c[2]) const for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) { for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) { - Port* f = _session->engine().get_port_by_name (*i); + boost::shared_ptr<Port> f = _session->engine().get_port_by_name (*i); /* since we are talking about an IO, our ports should all have an associated Port *, so the above call should never fail */ diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index dffda5bed4..39b1971080 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -993,7 +993,7 @@ MixerStrip::update_io_button (boost::shared_ptr<ARDOUR::Route> route, Width widt { uint32_t io_count; uint32_t io_index; - Port *port; + boost::shared_ptr<Port> port; vector<string> port_connections; uint32_t total_connection_count = 0; @@ -1185,8 +1185,15 @@ MixerStrip::diskstream_changed () } void -MixerStrip::port_connected_or_disconnected (Port* a, Port* b) +MixerStrip::port_connected_or_disconnected (boost::weak_ptr<Port> wa, boost::weak_ptr<Port> wb) { + boost::shared_ptr<Port> a = wa.lock (); + boost::shared_ptr<Port> b = wb.lock (); + + if (!a || !b) { + return; + } + if (_route->input()->has_port (a) || _route->input()->has_port (b)) { update_input_display (); set_width_enum (_width, this); diff --git a/gtk2_ardour/mixer_strip.h b/gtk2_ardour/mixer_strip.h index 3c123792f9..dd6dddf6ea 100644 --- a/gtk2_ardour/mixer_strip.h +++ b/gtk2_ardour/mixer_strip.h @@ -288,7 +288,7 @@ class MixerStrip : public RouteUI, public Gtk::EventBox static int scrollbar_height; void update_io_button (boost::shared_ptr<ARDOUR::Route> route, Width width, bool input_button); - void port_connected_or_disconnected (ARDOUR::Port *, ARDOUR::Port *); + void port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>); static std::string meter_point_string (ARDOUR::MeterPoint); }; diff --git a/gtk2_ardour/port_matrix.cc b/gtk2_ardour/port_matrix.cc index d7e2cfd7fa..9336d520e8 100644 --- a/gtk2_ardour/port_matrix.cc +++ b/gtk2_ardour/port_matrix.cc @@ -700,7 +700,7 @@ PortMatrix::remove_channel (ARDOUR::BundleChannel b) boost::shared_ptr<IO> io = io_from_bundle (b.bundle); if (io) { - Port* p = io->nth (b.channel); + boost::shared_ptr<Port> p = io->nth (b.channel); if (p) { int const r = io->remove_port (p, this); if (r == -1) { |