[vlma-devel] commit: Prevent race conditions on the log of commands which have been sent to servers . (Adrien Grand )

git version control git at videolan.org
Sun Aug 24 01:34:44 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Aug 24 01:29:45 2008 +0200| [611f6a4bb10800c884f666e1f19ea0384d02e733] | committer: Adrien Grand 

Prevent race conditions on the log of commands which have been sent to servers.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=611f6a4bb10800c884f666e1f19ea0384d02e733
---

 .../org/videolan/vlma/order/CommandLogger.java     |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/CommandLogger.java b/vlma-core/src/main/java/org/videolan/vlma/order/CommandLogger.java
index e909367..dcf3970 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/CommandLogger.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/CommandLogger.java
@@ -38,9 +38,11 @@ public class CommandLogger {
     private LinkedList<Command> commands = new LinkedList<Command>();
 
     public void add(Command command) {
-        commands.addFirst(command);
-        while (commands.size() > configuration.getInt("vlma.ui.command.queue.size")) {
-            commands.removeLast();
+        synchronized (commands) {
+            commands.addFirst(command);
+            while (commands.size() > configuration.getInt("vlma.ui.command.queue.size")) {
+                commands.removeLast();
+            }
         }
     }
 
@@ -54,7 +56,9 @@ public class CommandLogger {
      * @return the last commands sent
      */
     public List<Command> getCommands() {
-        return commands;
+        synchronized (commands) {
+            return commands;
+        }
     }
 
     /**



More information about the vlma-devel mailing list