[iagno] Take a mutex less often.



commit c63a02bf01ee691d186291eb3380816cb877d1d3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon May 6 07:33:19 2019 +0200

    Take a mutex less often.

 src/computer-reversi.vala | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/src/computer-reversi.vala b/src/computer-reversi.vala
index 94ad217..6491fe0 100644
--- a/src/computer-reversi.vala
+++ b/src/computer-reversi.vala
@@ -117,6 +117,11 @@ private class ComputerReversi : ComputerPlayer
                 x = ((!) move).x;
                 y = ((!) move).y;
             }
+
+            /* Checking move_pending here is optional. It helps avoid a long unnecessary search
+             * if the move has been cancelled, but is expensive because it requires taking a mutex. */
+            if (!move_pending)
+                return;
         }
     }
 
@@ -128,11 +133,6 @@ private class ComputerReversi : ComputerPlayer
             return g.n_current_tiles > g.n_opponent_tiles ? POSITIVE_INFINITY - (int16) g.n_opponent_tiles
                                                           : NEGATIVE_INFINITY + (int16) g.n_current_tiles;
 
-        /* Checking move_pending here is optional. It helps avoid a long unnecessary search
-         * if the move has been cancelled, but is expensive because it requires taking a mutex. */
-        if (!move_pending)
-            return 0;
-
         /* End of the search, calculate how good a result this is. */
         if (depth == 0)
             return calculate_heuristic (g, ref difficulty_level, ref heuristic);


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