Commit e2c81263713fb3868d9f85b99f8640ae3eba35b2

pizzocel 2014-12-06T02:06:57

Added a mutex protecting execution of MPD commands.

diff --git a/lib/mpd_client.rb b/lib/mpd_client.rb
index e6a1095..0f8c0f3 100644
--- a/lib/mpd_client.rb
+++ b/lib/mpd_client.rb
@@ -154,6 +154,7 @@ class MPDClient
   end
 
   def initialize
+    @mutex = Mutex.new
     reset
   end
 
@@ -203,12 +204,14 @@ class MPDClient
   private
 
   def execute(command, *args, retval)
-    if !@command_list.nil?
-      write_command(command, *args)
-      @command_list << retval
-    else
-      write_command(command, *args)
-      eval retval
+    @mutex.synchronize do
+      if !@command_list.nil?
+        write_command(command, *args)
+        @command_list << retval
+      else
+        write_command(command, *args)
+        eval retval
+      end
     end
   end