mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Reformat and simplify previous patch
No functional change.
This commit is contained in:
parent
f6e98a924a
commit
7e3dba4f4c
3 changed files with 39 additions and 50 deletions
|
@ -987,7 +987,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
|||
&& Threads.size() >= 2
|
||||
&& depth >= Threads.minimumSplitDepth
|
||||
&& ( !thisThread->activeSplitPoint
|
||||
|| !thisThread->activeSplitPoint->allowLatejoin)
|
||||
|| !thisThread->activeSplitPoint->allSlavesSearching)
|
||||
&& thisThread->splitPointsSize < MAX_SPLITPOINTS_PER_THREAD)
|
||||
{
|
||||
assert(bestValue > -VALUE_INFINITE && bestValue < beta);
|
||||
|
@ -1529,9 +1529,10 @@ void Thread::idle_loop() {
|
|||
|
||||
assert(searching);
|
||||
|
||||
searching = false;
|
||||
activePosition = NULL;
|
||||
sp->slavesMask.reset(idx);
|
||||
sp->allowLatejoin = false;
|
||||
sp->allSlavesSearching = false;
|
||||
sp->nodes += pos.nodes_searched();
|
||||
|
||||
// Wake up the master thread so to allow it to return from the idle
|
||||
|
@ -1550,9 +1551,36 @@ void Thread::idle_loop() {
|
|||
// if we are exiting there is a chance that they are already freed.
|
||||
sp->mutex.unlock();
|
||||
|
||||
// Try to late join to another splitpoint
|
||||
if (Threads.size() <= 2 || !attempt_to_latejoin()) // FIXME: attempt_to_latejoin() is theoretically unsafe when were are exiting the program...
|
||||
searching = false;
|
||||
// Try to late join to another split point if none of its slaves has
|
||||
// already finished.
|
||||
if (Threads.size() > 2)
|
||||
for (size_t i = 0; i < Threads.size(); ++i)
|
||||
{
|
||||
int size = Threads[i]->splitPointsSize; // Local copy
|
||||
sp = size ? &Threads[i]->splitPoints[size - 1] : NULL;
|
||||
|
||||
if ( sp
|
||||
&& sp->allSlavesSearching
|
||||
&& available_to(Threads[i]))
|
||||
{
|
||||
// Recheck the conditions under lock protection
|
||||
Threads.mutex.lock();
|
||||
sp->mutex.lock();
|
||||
|
||||
if ( sp->allSlavesSearching
|
||||
&& available_to(Threads[i]))
|
||||
{
|
||||
sp->slavesMask.set(idx);
|
||||
activeSplitPoint = sp;
|
||||
searching = true;
|
||||
}
|
||||
|
||||
sp->mutex.unlock();
|
||||
Threads.mutex.unlock();
|
||||
|
||||
break; // Just a single attempt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If this thread is the master of a split point and all slaves have finished
|
||||
|
@ -1568,44 +1596,6 @@ void Thread::idle_loop() {
|
|||
}
|
||||
}
|
||||
|
||||
bool Thread::attempt_to_latejoin()
|
||||
{
|
||||
SplitPoint *sp;
|
||||
size_t i;
|
||||
bool success = false;
|
||||
|
||||
for (i = 0; i < Threads.size(); ++i)
|
||||
{
|
||||
int size = Threads[i]->splitPointsSize; // Make a local copy to prevent size from changing under our feet.
|
||||
|
||||
sp = size ? &Threads[i]->splitPoints[size - 1] : NULL;
|
||||
|
||||
if ( sp
|
||||
&& sp->allowLatejoin
|
||||
&& available_to(Threads[i], true))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == Threads.size())
|
||||
return false; // No suitable splitpoint found!
|
||||
|
||||
// Recheck conditions under lock protection
|
||||
Threads.mutex.lock();
|
||||
sp->mutex.lock();
|
||||
|
||||
if ( sp->allowLatejoin
|
||||
&& available_to(Threads[i], true))
|
||||
{
|
||||
activeSplitPoint = sp;
|
||||
sp->slavesMask.set(this->idx);
|
||||
success = true;
|
||||
}
|
||||
|
||||
sp->mutex.unlock();
|
||||
Threads.mutex.unlock();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/// check_time() is called by the timer thread when the timer triggers. It is
|
||||
/// used to print debug info and, more importantly, to detect when we are out of
|
||||
|
|
|
@ -112,9 +112,9 @@ bool Thread::cutoff_occurred() const {
|
|||
// which are busy searching the split point at the top of slave's split point
|
||||
// stack (the "helpful master concept" in YBWC terminology).
|
||||
|
||||
bool Thread::available_to(const Thread* master, bool latejoin) const {
|
||||
bool Thread::available_to(const Thread* master) const {
|
||||
|
||||
if (searching && !latejoin)
|
||||
if (searching)
|
||||
return false;
|
||||
|
||||
// Make a local copy to be sure it doesn't become zero under our feet while
|
||||
|
@ -239,7 +239,7 @@ void ThreadPool::read_uci_options() {
|
|||
Thread* ThreadPool::available_slave(const Thread* master) const {
|
||||
|
||||
for (const_iterator it = begin(); it != end(); ++it)
|
||||
if ((*it)->available_to(master, false))
|
||||
if ((*it)->available_to(master))
|
||||
return *it;
|
||||
|
||||
return NULL;
|
||||
|
@ -292,7 +292,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu
|
|||
Threads.mutex.lock();
|
||||
sp.mutex.lock();
|
||||
|
||||
sp.allowLatejoin = true; // Only set this under lock protection
|
||||
sp.allSlavesSearching = true; // Must be set under lock protection
|
||||
++splitPointsSize;
|
||||
activeSplitPoint = &sp;
|
||||
activePosition = NULL;
|
||||
|
|
|
@ -77,7 +77,7 @@ struct SplitPoint {
|
|||
// Shared data
|
||||
Mutex mutex;
|
||||
std::bitset<MAX_THREADS> slavesMask;
|
||||
volatile bool allowLatejoin;
|
||||
volatile bool allSlavesSearching;
|
||||
volatile uint64_t nodes;
|
||||
volatile Value alpha;
|
||||
volatile Value bestValue;
|
||||
|
@ -114,9 +114,8 @@ struct Thread : public ThreadBase {
|
|||
|
||||
Thread();
|
||||
virtual void idle_loop();
|
||||
bool attempt_to_latejoin();
|
||||
bool cutoff_occurred() const;
|
||||
bool available_to(const Thread* master, bool latejoin) const;
|
||||
bool available_to(const Thread* master) const;
|
||||
|
||||
template <bool Fake>
|
||||
void split(Position& pos, const Search::Stack* ss, Value alpha, Value beta, Value* bestValue, Move* bestMove,
|
||||
|
|
Loading…
Add table
Reference in a new issue