]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Move sleepLock and sleepCond under Thread
[stockfish] / src / search.cpp
index 516f2d051cc503f058d2f541a7d46ef9fcb8800e..af895a376388890827fc4277e842ae036cc697c8 100644 (file)
@@ -83,14 +83,13 @@ namespace {
                Depth depth, Move threatMove, int moveCount, MovePicker* mp, bool pvNode);
 
   private:
+    Lock mpLock;
     Depth minimumSplitDepth;
     int maxThreadsPerSplitPoint;
     bool useSleepingThreads;
     int activeThreads;
     volatile bool allThreadsShouldExit;
     Thread threads[MAX_THREADS];
-    Lock mpLock, sleepLock[MAX_THREADS];
-    WaitCondition sleepCond[MAX_THREADS];
   };
 
 
@@ -596,7 +595,7 @@ namespace {
     SearchStack ss[PLY_MAX_PLUS_2];
     Value bestValues[PLY_MAX_PLUS_2];
     int bestMoveChanges[PLY_MAX_PLUS_2];
-    int depth, aspirationDelta, skillSamplingDepth;
+    int depth, aspirationDelta;
     Value value, alpha, beta;
     Move bestMove, easyMove, skillBest, skillPonder;
 
@@ -605,7 +604,7 @@ namespace {
     TT.new_search();
     H.clear();
     *ponderMove = bestMove = easyMove = skillBest = skillPonder = MOVE_NONE;
-    depth = aspirationDelta = skillSamplingDepth = 0;
+    depth = aspirationDelta = 0;
     alpha = -VALUE_INFINITE, beta = VALUE_INFINITE;
     ss->currentMove = MOVE_NULL; // Hack to skip update_gains()
 
@@ -622,11 +621,6 @@ namespace {
         return MOVE_NONE;
     }
 
-    // Choose a random sampling depth according to SkillLevel so that at low
-    // skills there is an higher risk to pick up a blunder.
-    if (SkillLevelEnabled)
-        skillSamplingDepth = 4 + SkillLevel + (RK.rand<unsigned>() % 4);
-
     // Iterative deepening loop
     while (++depth <= PLY_MAX && (!MaxDepth || depth <= MaxDepth) && !StopRequest)
     {
@@ -690,7 +684,7 @@ namespace {
         bestMoveChanges[depth] = Rml.bestMoveChanges;
 
         // Do we need to pick now the best and the ponder moves ?
-        if (SkillLevelEnabled && depth == skillSamplingDepth)
+        if (SkillLevelEnabled && depth == 1 + SkillLevel)
             do_skill_level(&skillBest, &skillPonder);
 
         // Send PV line to GUI and to log file
@@ -2052,7 +2046,7 @@ split_point_start: // At split points actual search starts from here
                 threads[threadID].state = THREAD_AVAILABLE;
 
             // Grab the lock to avoid races with wake_sleeping_thread()
-            lock_grab(&sleepLock[threadID]);
+            lock_grab(&threads[threadID].sleepLock);
 
             // If we are master and all slaves have finished do not go to sleep
             for (i = 0; sp && i < activeThreads && !sp->slaves[i]; i++) {}
@@ -2060,15 +2054,15 @@ split_point_start: // At split points actual search starts from here
 
             if (allFinished || allThreadsShouldExit)
             {
-                lock_release(&sleepLock[threadID]);
+                lock_release(&threads[threadID].sleepLock);
                 break;
             }
 
             // Do sleep here after retesting sleep conditions
             if (threadID >= activeThreads || threads[threadID].state == THREAD_AVAILABLE)
-                cond_wait(&sleepCond[threadID], &sleepLock[threadID]);
+                cond_wait(&threads[threadID].sleepCond, &threads[threadID].sleepLock);
 
-            lock_release(&sleepLock[threadID]);
+            lock_release(&threads[threadID].sleepLock);
         }
 
         // If this thread has been assigned work, launch a search
@@ -2139,8 +2133,8 @@ split_point_start: // At split points actual search starts from here
 
     for (i = 0; i < MAX_THREADS; i++)
     {
-        lock_init(&sleepLock[i]);
-        cond_init(&sleepCond[i]);
+        lock_init(&threads[i].sleepLock);
+        cond_init(&threads[i].sleepCond);
     }
 
     // Initialize splitPoints[] locks
@@ -2207,8 +2201,8 @@ split_point_start: // At split points actual search starts from here
     // Now we can safely destroy the wait conditions
     for (int i = 0; i < MAX_THREADS; i++)
     {
-        lock_destroy(&sleepLock[i]);
-        cond_destroy(&sleepCond[i]);
+        lock_destroy(&threads[i].sleepLock);
+        cond_destroy(&threads[i].sleepCond);
     }
   }
 
@@ -2397,9 +2391,9 @@ split_point_start: // At split points actual search starts from here
 
   void ThreadsManager::wake_sleeping_thread(int threadID) {
 
-     lock_grab(&sleepLock[threadID]);
-     cond_signal(&sleepCond[threadID]);
-     lock_release(&sleepLock[threadID]);
+     lock_grab(&threads[threadID].sleepLock);
+     cond_signal(&threads[threadID].sleepCond);
+     lock_release(&threads[threadID].sleepLock);
   }