mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Avoid a needless locking in sp_search()
Only in less then 2% of cases we have a new sp->bestValue, so check before to lock and save a costly locking most of the times. Patch suggested by Joona. No functional search. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
f0b0a3b135
commit
51c3af9dd0
1 changed files with 14 additions and 11 deletions
|
@ -1759,21 +1759,24 @@ namespace {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// New best move?
|
// New best move?
|
||||||
lock_grab(&(sp->lock));
|
if (value > sp->bestValue) // Less then 2% of cases
|
||||||
if (value > sp->bestValue && !thread_should_stop(threadID))
|
|
||||||
{
|
{
|
||||||
sp->bestValue = value;
|
lock_grab(&(sp->lock));
|
||||||
if (sp->bestValue >= sp->beta)
|
if (value > sp->bestValue && !thread_should_stop(threadID))
|
||||||
{
|
{
|
||||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
sp->bestValue = value;
|
||||||
for (int i = 0; i < ActiveThreads; i++)
|
if (sp->bestValue >= sp->beta)
|
||||||
if (i != threadID && (i == sp->master || sp->slaves[i]))
|
{
|
||||||
Threads[i].stop = true;
|
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||||
|
for (int i = 0; i < ActiveThreads; i++)
|
||||||
|
if (i != threadID && (i == sp->master || sp->slaves[i]))
|
||||||
|
Threads[i].stop = true;
|
||||||
|
|
||||||
sp->finished = true;
|
sp->finished = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
lock_release(&(sp->lock));
|
||||||
}
|
}
|
||||||
lock_release(&(sp->lock));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_grab(&(sp->lock));
|
lock_grab(&(sp->lock));
|
||||||
|
|
Loading…
Add table
Reference in a new issue