From 88f6395134c7b8e6fee9168580d43afb7b9bbb55 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 16 May 2012 00:16:34 +0000 Subject: 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 --- libs/ardour/ardour/playlist.h | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'libs/ardour/ardour/playlist.h') 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 > all_regions; /* all regions ever added to this playlist */ @@ -365,8 +370,9 @@ public: virtual void pre_uncombine (std::vector >&, boost::shared_ptr) {} 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 &); -- cgit v1.2.3