]> git.sesse.net Git - stockfish/blobdiff - src/thread.cpp
Little reformat of elapsed_search_time()
[stockfish] / src / thread.cpp
index 57faa6e90bb39b53ccff0a3cf3f5c6e84ef6f225..06646a7b99b131d9751ccdc7b951dd9f6a631bb5 100644 (file)
@@ -418,7 +418,7 @@ void Thread::main_loop() {
       if (do_terminate)
           return;
 
-      think(); // Search entry point
+      Search::think();
   }
 }
 
@@ -428,8 +428,8 @@ void Thread::main_loop() {
 // then function returns immediately, otherwise caller is blocked waiting for
 // the search to finish.
 
-void ThreadsManager::start_thinking(bool asyncMode) {
-
+void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsType& limits,
+                                    const std::vector<Move>& searchMoves, bool asyncMode) {
   Thread& main = threads[0];
 
   lock_grab(&main.sleepLock);
@@ -438,6 +438,14 @@ void ThreadsManager::start_thinking(bool asyncMode) {
   while (!main.do_sleep)
       cond_wait(&sleepCond, &main.sleepLock);
 
+  // Copy input arguments to Search global variables
+  Search::RootPosition.copy(pos, 0);
+  Search::Limits = limits;
+  Search::RootMoves = searchMoves;
+
+  // Reset signals before to start the search
+  memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
+
   main.do_sleep = false;
   cond_signal(&main.sleepCond); // Wake up main thread
 
@@ -446,3 +454,25 @@ void ThreadsManager::start_thinking(bool asyncMode) {
 
   lock_release(&main.sleepLock);
 }
+
+
+// ThreadsManager::wait_for_stop_or_ponderhit() is called when the maximum depth
+// is reached while the program is pondering. The point is to work around a wrinkle
+// in the UCI protocol: When pondering, the engine is not allowed to give a
+// "bestmove" before the GUI sends it a "stop" or "ponderhit" command.
+// We simply wait here until one of these commands (that raise StopRequest) is
+// sent, and return, after which the bestmove and pondermove will be printed.
+
+void ThreadsManager::wait_for_stop_or_ponderhit() {
+
+  Search::Signals.stopOnPonderhit = true;
+
+  Thread& main = threads[0];
+
+  lock_grab(&main.sleepLock);
+
+  while (!Search::Signals.stop)
+      cond_wait(&main.sleepCond, &main.sleepLock);
+
+  lock_release(&main.sleepLock);
+}