From 57d0aa4354590e2b9f46fee263c47dd17d9e45e8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 9 Jul 2014 10:18:28 -0400 Subject: [PATCH] add mutex to prevent concurrent session state saves. Why wasn't this done 10 years ago? --- libs/ardour/ardour/session.h | 1 + libs/ardour/session_state.cc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 40b76b4ea9..6314dda1cd 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1135,6 +1135,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop friend class StateProtector; gint _suspend_save; /* atomic */ volatile bool _save_queued; + Glib::Threads::Mutex save_state_lock; int load_options (const XMLNode&); int load_state (std::string snapshot_name); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 4e4678ce73..12d4779c60 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -689,6 +689,10 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot XMLTree tree; std::string xml_path(_session_dir->root_path()); + /* prevent concurrent saves from different threads */ + + Glib::Threads::Mutex::Lock lm (save_state_lock); + if (!_writable || (_state_of_the_state & CannotSave)) { return 1; }