1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 17:49:35 +00:00

Prefer a reference to a pointer

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-08-20 07:54:38 +01:00
parent e8b7109eff
commit ab65d3fd0e

View file

@ -55,7 +55,7 @@ Thread::Thread(Fn fn) {
lock_init(sleepLock); lock_init(sleepLock);
cond_init(sleepCond); cond_init(sleepCond);
for (size_t j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++) for (int j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++)
lock_init(splitPoints[j].lock); lock_init(splitPoints[j].lock);
if (!thread_create(handle, start_routine, this)) if (!thread_create(handle, start_routine, this))
@ -314,41 +314,41 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
return bestValue; return bestValue;
// Pick the next available split point from the split point stack // Pick the next available split point from the split point stack
SplitPoint* sp = &master->splitPoints[master->splitPointsCnt]; SplitPoint& sp = master->splitPoints[master->splitPointsCnt];
sp->parent = master->curSplitPoint; sp.parent = master->curSplitPoint;
sp->master = master; sp.master = master;
sp->cutoff = false; sp.cutoff = false;
sp->slavesMask = 1ULL << master->idx; sp.slavesMask = 1ULL << master->idx;
sp->depth = depth; sp.depth = depth;
sp->bestMove = *bestMove; sp.bestMove = *bestMove;
sp->threatMove = threatMove; sp.threatMove = threatMove;
sp->alpha = alpha; sp.alpha = alpha;
sp->beta = beta; sp.beta = beta;
sp->nodeType = nodeType; sp.nodeType = nodeType;
sp->bestValue = bestValue; sp.bestValue = bestValue;
sp->mp = mp; sp.mp = mp;
sp->moveCount = moveCount; sp.moveCount = moveCount;
sp->pos = &pos; sp.pos = &pos;
sp->nodes = 0; sp.nodes = 0;
sp->ss = ss; sp.ss = ss;
assert(master->is_searching); assert(master->is_searching);
master->curSplitPoint = sp; master->curSplitPoint = &sp;
int slavesCnt = 0; int slavesCnt = 0;
// Try to allocate available threads and ask them to start searching setting // Try to allocate available threads and ask them to start searching setting
// is_searching flag. This must be done under lock protection to avoid concurrent // is_searching flag. This must be done under lock protection to avoid concurrent
// allocation of the same slave by another master. // allocation of the same slave by another master.
lock_grab(sp->lock); lock_grab(sp.lock);
lock_grab(splitLock); lock_grab(splitLock);
for (size_t i = 0; i < size() && !Fake; ++i) for (size_t i = 0; i < size() && !Fake; ++i)
if (threads[i]->is_available_to(master)) if (threads[i]->is_available_to(master))
{ {
sp->slavesMask |= 1ULL << i; sp.slavesMask |= 1ULL << i;
threads[i]->curSplitPoint = sp; threads[i]->curSplitPoint = &sp;
threads[i]->is_searching = true; // Slave leaves idle_loop() threads[i]->is_searching = true; // Slave leaves idle_loop()
if (useSleepingThreads) if (useSleepingThreads)
@ -361,7 +361,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
master->splitPointsCnt++; master->splitPointsCnt++;
lock_release(splitLock); lock_release(splitLock);
lock_release(sp->lock); lock_release(sp.lock);
// Everything is set up. The master thread enters the idle loop, from which // Everything is set up. The master thread enters the idle loop, from which
// it will instantly launch a search, because its is_searching flag is set. // it will instantly launch a search, because its is_searching flag is set.
@ -379,19 +379,19 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
// We have returned from the idle loop, which means that all threads are // We have returned from the idle loop, which means that all threads are
// finished. Note that setting is_searching and decreasing splitPointsCnt is // finished. Note that setting is_searching and decreasing splitPointsCnt is
// done under lock protection to avoid a race with Thread::is_available_to(). // done under lock protection to avoid a race with Thread::is_available_to().
lock_grab(sp->lock); // To protect sp->nodes lock_grab(sp.lock); // To protect sp.nodes
lock_grab(splitLock); lock_grab(splitLock);
master->is_searching = true; master->is_searching = true;
master->splitPointsCnt--; master->splitPointsCnt--;
master->curSplitPoint = sp->parent; master->curSplitPoint = sp.parent;
pos.set_nodes_searched(pos.nodes_searched() + sp->nodes); pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
*bestMove = sp->bestMove; *bestMove = sp.bestMove;
lock_release(splitLock); lock_release(splitLock);
lock_release(sp->lock); lock_release(sp.lock);
return sp->bestValue; return sp.bestValue;
} }
// Explicit template instantiations // Explicit template instantiations