diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-05-16 00:16:34 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-05-16 00:16:34 +0000 |
commit | 88f6395134c7b8e6fee9168580d43afb7b9bbb55 (patch) | |
tree | ac4e661b985bf3bce8d05cb6fb43f3cc6bb28bf0 /libs/ardour/ardour/playlist.h | |
parent | 674a7b3ac01eaa0d65c3db693135b483b2b15998 (diff) |
switch to a RWLock for Playlist, to allow simultaneous reads (which can happen occasionally, eg. peak and butler threads)
git-svn-id: svn://localhost/ardour2/branches/3.0@12301 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/playlist.h')
-rw-r--r-- | libs/ardour/ardour/playlist.h | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index 9a76ec56ad..f7e1c40bae 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -230,25 +230,30 @@ public: friend class Session; protected: - struct RegionLock { - RegionLock (Playlist *pl, bool do_block_notify = true) : playlist (pl), block_notify (do_block_notify) { - if (!playlist->region_lock.trylock()) { - std::cerr << "Lock for playlist " << pl->name() << " already held\n"; - PBD::stacktrace (std::cerr, 10); - } - if (block_notify) { - playlist->delay_notifications(); - } - } - ~RegionLock() { - playlist->region_lock.unlock(); - if (block_notify) { - playlist->release_notifications (); - } - } - Playlist *playlist; - bool block_notify; - }; + struct RegionReadLock : public Glib::RWLock::ReaderLock { + RegionReadLock (Playlist *pl) : Glib::RWLock::ReaderLock (pl->region_lock) {} + ~RegionReadLock() { Glib::RWLock::ReaderLock::release (); } + }; + + struct RegionWriteLock : public Glib::RWLock::WriterLock { + RegionWriteLock (Playlist *pl, bool do_block_notify = true) + : Glib::RWLock::WriterLock (pl->region_lock) + , playlist (pl) + , block_notify (do_block_notify) { + if (block_notify) { + playlist->delay_notifications(); + } + } + + ~RegionWriteLock() { + Glib::RWLock::WriterLock::release (); + if (block_notify) { + playlist->release_notifications (); + } + } + Playlist *playlist; + bool block_notify; + }; RegionListProperty regions; /* the current list of regions in the playlist */ std::set<boost::shared_ptr<Region> > all_regions; /* all regions ever added to this playlist */ @@ -365,8 +370,9 @@ public: virtual void pre_uncombine (std::vector<boost::shared_ptr<Region> >&, boost::shared_ptr<Region>) {} private: - friend class RegionLock; - mutable Glib::Mutex region_lock; + friend class RegionReadLock; + friend class RegionWriteLock; + mutable Glib::RWLock region_lock; private: void setup_layering_indices (RegionList const &); |