[gnome-chess] Fix massive CPU usage after starting a new game



commit f770ab7e90b1952a6b92e3be14d21a81a08bae5b
Author: Michael Catanzaro <mike catanzaro gmail com>
Date:   Sat May 25 13:41:11 2013 -0500

    Fix massive CPU usage after starting a new game
    
    After ending a game against a chess engine, CPU usage would skyrocket
    since the IOWatch on the engine's stdout wasn't removed from the main
    loop. Remedy this.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=578130#c7

 src/chess-engine.vala |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/src/chess-engine.vala b/src/chess-engine.vala
index 8031c27..1a63e83 100644
--- a/src/chess-engine.vala
+++ b/src/chess-engine.vala
@@ -7,6 +7,7 @@ public abstract class ChessEngine : Object
     private int stdin_fd;
     private int stderr_fd;
     private IOChannel stdout_channel;
+    private uint stdout_watch_id;
 
     protected virtual void process_input (char[] data) {}
 
@@ -64,7 +65,7 @@ public abstract class ChessEngine : Object
         {
             stderr.printf ("Failed to set input from chess engine to non-blocking: %s", e.message);
         }
-        stdout_channel.add_watch (IOCondition.IN, read_cb);
+        stdout_watch_id = stdout_channel.add_watch (IOCondition.IN, read_cb);
 
         starting ();
 
@@ -86,6 +87,9 @@ public abstract class ChessEngine : Object
 
     public void stop ()
     {
+        if (stdout_watch_id > 0)
+            Source.remove (stdout_watch_id);
+
         if (pid != 0)
         {
             Posix.kill (pid, Posix.SIGTERM);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]