- assert(pos.thread() >= 0 && pos.thread() < activeThreads);
- assert(activeThreads > 1);
-
- int i, master = pos.thread();
- Thread& masterThread = threads[master];
-
- // If we already have too many active split points, don't split
- if (masterThread.activeSplitPoints >= MAX_ACTIVE_SPLIT_POINTS)
- return;
-
- // Pick the next available split point object from the split point stack
- SplitPoint& splitPoint = masterThread.splitPoints[masterThread.activeSplitPoints];
-
- // Initialize the split point object
- splitPoint.parent = masterThread.splitPoint;
- splitPoint.master = master;
- splitPoint.is_betaCutoff = false;
- splitPoint.depth = depth;
- splitPoint.threatMove = threatMove;
- splitPoint.alpha = *alpha;
- splitPoint.beta = beta;
- splitPoint.nodeType = nodeType;
- splitPoint.bestValue = *bestValue;
- splitPoint.mp = mp;
- splitPoint.moveCount = moveCount;
- splitPoint.pos = &pos;
- splitPoint.nodes = 0;
- splitPoint.ss = ss;
- for (i = 0; i < activeThreads; i++)
- splitPoint.is_slave[i] = false;
-
- // If we are here it means we are not available
- assert(masterThread.state == Thread::SEARCHING);
-
- int booked = 0;
-
- // Try to allocate available threads setting state to Thread::BOOKED, this
- // must be done under lock protection to avoid concurrent allocation of
- // the same slave by another master.
- lock_grab(&threadsLock);
-
- for (i = 0; !Fake && i < activeThreads && booked < maxThreadsPerSplitPoint; i++)
- if (i != master && threads[i].is_available_to(master))
+
+ Thread& master = pos.this_thread();
+
+ if (master.splitPointsCnt >= MAX_SPLITPOINTS_PER_THREAD)
+ return bestValue;
+
+ // Pick the next available split point from the split point stack
+ SplitPoint* sp = &master.splitPoints[master.splitPointsCnt++];
+
+ sp->parent = master.curSplitPoint;
+ sp->master = &master;
+ sp->cutoff = false;
+ sp->slavesMask = 1ULL << master.idx;
+ sp->depth = depth;
+ sp->bestMove = *bestMove;
+ sp->threatMove = threatMove;
+ sp->alpha = alpha;
+ sp->beta = beta;
+ sp->nodeType = nodeType;
+ sp->bestValue = bestValue;
+ sp->mp = mp;
+ sp->moveCount = moveCount;
+ sp->pos = &pos;
+ sp->nodes = 0;
+ sp->ss = ss;
+
+ assert(master.is_searching);
+
+ master.curSplitPoint = sp;
+ int slavesCnt = 0;
+
+ // 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
+ // allocation of the same slave by another master.
+ lock_grab(sp->lock);
+ lock_grab(splitLock);
+
+ for (int i = 0; i < size() && !Fake; ++i)
+ if (threads[i]->is_available_to(master))