From d96a3aa5b774c21669c583e93a6c48da9f3fe96e Mon Sep 17 00:00:00 2001
From: Arseniy Shestakov <me@arseniyshestakov.com>
Date: Thu, 14 Sep 2017 11:57:19 +0300
Subject: [PATCH] CAudioBase: move mutex to base class since CSoundHandler need
 it

---
 client/CMusicHandler.cpp | 10 ++++++----
 client/CMusicHandler.h   |  4 +---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp
index a01c52775..948d24de1 100644
--- a/client/CMusicHandler.cpp
+++ b/client/CMusicHandler.cpp
@@ -281,6 +281,7 @@ bool CSoundHandler::ambientCheckVisitable() const
 
 void CSoundHandler::ambientUpdateChannels(std::map<std::string, int> sounds)
 {
+	boost::mutex::scoped_lock guard(mutex);
 	std::vector<std::string> stoppedSounds;
 	for(auto & pair : ambientChannels)
 	{
@@ -310,6 +311,7 @@ void CSoundHandler::ambientUpdateChannels(std::map<std::string, int> sounds)
 
 void CSoundHandler::ambientStopAllChannels()
 {
+	boost::mutex::scoped_lock guard(mutex);
 	for(auto ch : ambientChannels)
 	{
 		ambientStopSound(ch.first);
@@ -375,7 +377,7 @@ void CMusicHandler::release()
 {
 	if (initialized)
 	{
-		boost::mutex::scoped_lock guard(musicMutex);
+		boost::mutex::scoped_lock guard(mutex);
 
 		Mix_HookMusicFinished(nullptr);
 
@@ -439,7 +441,7 @@ void CMusicHandler::queueNext(std::unique_ptr<MusicEntry> queued)
 	if (!initialized)
 		return;
 
-	boost::mutex::scoped_lock guard(musicMutex);
+	boost::mutex::scoped_lock guard(mutex);
 
 	next = std::move(queued);
 
@@ -468,7 +470,7 @@ void CMusicHandler::stopMusic(int fade_ms)
 	if (!initialized)
 		return;
 
-	boost::mutex::scoped_lock guard(musicMutex);
+	boost::mutex::scoped_lock guard(mutex);
 
 	if (current.get() != nullptr)
 		current->stop(fade_ms);
@@ -485,7 +487,7 @@ void CMusicHandler::setVolume(ui32 percent)
 
 void CMusicHandler::musicFinishedCallback(void)
 {
-	boost::mutex::scoped_lock guard(musicMutex);
+	boost::mutex::scoped_lock guard(mutex);
 
 	if (current.get() != nullptr)
 	{
diff --git a/client/CMusicHandler.h b/client/CMusicHandler.h
index 3819020be..75bc8b596 100644
--- a/client/CMusicHandler.h
+++ b/client/CMusicHandler.h
@@ -20,6 +20,7 @@ struct Mix_Chunk;
 
 class CAudioBase {
 protected:
+	boost::mutex mutex;
 	bool initialized;
 	int volume;					// from 0 (mute) to 100
 
@@ -118,9 +119,6 @@ public:
 class CMusicHandler: public CAudioBase
 {
 private:
-	// Because we use the SDL music callback, our music variables must
-	// be protected
-	boost::mutex musicMutex;
 	//update volume on configuration change
 	SettingsListener listener;
 	void onVolumeChange(const JsonNode &volumeNode);