summaryrefslogtreecommitdiff
path: root/libs/ardour/export_channel.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2011-10-28 17:04:09 +0000
committerCarl Hetherington <carl@carlh.net>2011-10-28 17:04:09 +0000
commit7bdcc127e3e42bd76b997b56ecd938b1127d790b (patch)
treef1e9856094ee5a54cc28957508f2b693fbcd043a /libs/ardour/export_channel.cc
parentf65e3f287b48fef6d4fdb8c4456c0eada4c4431c (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 'libs/ardour/export_channel.cc')
-rw-r--r--libs/ardour/export_channel.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/libs/ardour/export_channel.cc b/libs/ardour/export_channel.cc
index 4593c4de9f..8f83c0a7fb 100644
--- a/libs/ardour/export_channel.cc
+++ b/libs/ardour/export_channel.cc
@@ -62,15 +62,17 @@ PortExportChannel::read (Sample const *& data, framecnt_t frames) const
assert(frames <= buffer_size);
if (ports.size() == 1) {
- data = (*ports.begin())->get_audio_buffer(frames).data();
+ boost::shared_ptr<AudioPort> p = ports.begin()->lock ();
+ data = p->get_audio_buffer(frames).data();
return;
}
memset (buffer.get(), 0, frames * sizeof (Sample));
for (PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) {
- if (*it != 0) {
- Sample* port_buffer = (*it)->get_audio_buffer(frames).data();
+ boost::shared_ptr<AudioPort> p = it->lock ();
+ if (p) {
+ Sample* port_buffer = p->get_audio_buffer(frames).data();
for (uint32_t i = 0; i < frames; ++i) {
buffer[i] += (float) port_buffer[i];
@@ -86,8 +88,9 @@ PortExportChannel::get_state (XMLNode * node) const
{
XMLNode * port_node;
for (PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) {
- if ((port_node = node->add_child ("Port"))) {
- port_node->add_property ("name", (*it)->name());
+ boost::shared_ptr<Port> p = it->lock ();
+ if (p && (port_node = node->add_child ("Port"))) {
+ port_node->add_property ("name", p->name());
}
}
}
@@ -100,7 +103,7 @@ PortExportChannel::set_state (XMLNode * node, Session & session)
for (XMLNodeList::iterator it = xml_ports.begin(); it != xml_ports.end(); ++it) {
if ((prop = (*it)->property ("name"))) {
std::string const & name = prop->value();
- AudioPort * port = dynamic_cast<AudioPort *> (session.engine().get_port_by_name (name));
+ boost::shared_ptr<AudioPort> port = boost::dynamic_pointer_cast<AudioPort> (session.engine().get_port_by_name (name));
if (port) {
ports.insert (port);
} else {