@@ -29,6 +29,8 @@ using namespace Search;
2929
3030ThreadPool Threads; // Global object
3131
32+ extern void check_time ();
33+
3234namespace {
3335
3436 // start_routine() is the C function which is called when a new thread
@@ -90,9 +92,43 @@ Thread::Thread() /* : splitPoints() */ { // Value-initialization bug in MSVC
9092}
9193
9294
95+ // Thread::cutoff_occurred() checks whether a beta cutoff has occurred in the
96+ // current active split point, or in some ancestor of the split point.
97+
98+ bool Thread::cutoff_occurred () const {
99+
100+ for (SplitPoint* sp = activeSplitPoint; sp; sp = sp->parentSplitPoint )
101+ if (sp->cutoff )
102+ return true ;
103+
104+ return false ;
105+ }
106+
107+
108+ // Thread::available_to() checks whether the thread is available to help the
109+ // thread 'master' at a split point. An obvious requirement is that thread must
110+ // be idle. With more than two threads, this is not sufficient: If the thread is
111+ // the master of some split point, it is only available as a slave to the slaves
112+ // which are busy searching the split point at the top of slave's split point
113+ // stack (the "helpful master concept" in YBWC terminology).
114+
115+ bool Thread::available_to (const Thread* master) const {
116+
117+ if (searching)
118+ return false ;
119+
120+ // Make a local copy to be sure it doesn't become zero under our feet while
121+ // testing next condition and so leading to an out of bounds access.
122+ int size = splitPointsSize;
123+
124+ // No split points means that the thread is available as a slave for any
125+ // other thread otherwise apply the "helpful master" concept if possible.
126+ return !size || (splitPoints[size - 1 ].slavesMask & (1ULL << master->idx ));
127+ }
128+
129+
93130// TimerThread::idle_loop() is where the timer thread waits msec milliseconds
94131// and then calls check_time(). If msec is 0 thread sleeps until it's woken up.
95- extern void check_time ();
96132
97133void TimerThread::idle_loop () {
98134
@@ -144,41 +180,6 @@ void MainThread::idle_loop() {
144180}
145181
146182
147- // Thread::cutoff_occurred() checks whether a beta cutoff has occurred in the
148- // current active split point, or in some ancestor of the split point.
149-
150- bool Thread::cutoff_occurred () const {
151-
152- for (SplitPoint* sp = activeSplitPoint; sp; sp = sp->parentSplitPoint )
153- if (sp->cutoff )
154- return true ;
155-
156- return false ;
157- }
158-
159-
160- // Thread::available_to() checks whether the thread is available to help the
161- // thread 'master' at a split point. An obvious requirement is that thread must
162- // be idle. With more than two threads, this is not sufficient: If the thread is
163- // the master of some split point, it is only available as a slave to the slaves
164- // which are busy searching the split point at the top of slave's split point
165- // stack (the "helpful master concept" in YBWC terminology).
166-
167- bool Thread::available_to (const Thread* master) const {
168-
169- if (searching)
170- return false ;
171-
172- // Make a local copy to be sure it doesn't become zero under our feet while
173- // testing next condition and so leading to an out of bounds access.
174- int size = splitPointsSize;
175-
176- // No split points means that the thread is available as a slave for any
177- // other thread otherwise apply the "helpful master" concept if possible.
178- return !size || (splitPoints[size - 1 ].slavesMask & (1ULL << master->idx ));
179- }
180-
181-
182183// init() is called at startup to create and launch requested threads, that will
183184// go immediately to sleep due to 'sleepWhileIdle' set to true. We cannot use
184185// a c'tor because Threads is a static object and we need a fully initialized
@@ -264,8 +265,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu
264265 MovePicker* movePicker, int nodeType, bool cutNode) {
265266
266267 assert (pos.pos_is_ok ());
267- assert (*bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
268- assert (*bestValue > -VALUE_INFINITE);
268+ assert (-VALUE_INFINITE < *bestValue && *bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
269269 assert (depth >= Threads.minimumSplitDepth );
270270 assert (searching);
271271 assert (splitPointsSize < MAX_SPLITPOINTS_PER_THREAD);
@@ -367,8 +367,8 @@ void ThreadPool::wait_for_think_finished() {
367367// start_thinking() wakes up the main thread sleeping in MainThread::idle_loop()
368368// so to start a new search, then returns immediately.
369369
370- void ThreadPool::start_thinking (const Position& pos, const LimitsType& limits,
371- const std::vector<Move>& searchMoves, StateStackPtr& states) {
370+ void ThreadPool::start_thinking (const Position& pos, const LimitsType& limits, StateStackPtr& states) {
371+
372372 wait_for_think_finished ();
373373
374374 SearchTime = Time::now (); // As early as possible
@@ -386,8 +386,8 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
386386 }
387387
388388 for (MoveList<LEGAL> it (pos); *it; ++it)
389- if ( searchMoves .empty ()
390- || std::count (searchMoves. begin (), searchMoves .end (), *it))
389+ if ( limits. searchmoves .empty ()
390+ || std::count (limits. searchmoves . begin (), limits. searchmoves .end (), *it))
391391 RootMoves.push_back (RootMove (*it));
392392
393393 main ()->thinking = true ;
0 commit comments