X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=9cd63d9595476eeb2cd37bf2e7c7530a93b83a51;hp=faa3a5716aa1570945c5dcaea7cb345ca0e75455;hb=ef0496ff4095330eaea4b33bb14e0386942fd093;hpb=5a2d525048ca5eec1d5d0effc8868cb2fdc701bb diff --git a/src/thread.cpp b/src/thread.cpp index faa3a571..9cd63d95 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -34,15 +34,11 @@ namespace { extern "C" { // start_routine() is the C function which is called when a new thread // is launched. It is a wrapper to member function pointed by start_fn. - long start_routine(Thread* th) { - - Threads.set_this_thread(th); // Save pointer into thread local storage - (th->*(th->start_fn))(); - return 0; - } + long start_routine(Thread* th) { (th->*(th->start_fn))(); return 0; } } } + // Thread c'tor starts a newly-created thread of execution that will call // the idle loop function pointed by start_fn going immediately to sleep. @@ -205,12 +201,10 @@ bool Thread::is_available_to(Thread* master) const { void ThreadsManager::init() { - tls_init(tlsKey); cond_init(sleepCond); lock_init(splitLock); timer = new Thread(&Thread::timer_loop); threads.push_back(new Thread(&Thread::main_loop)); - set_this_thread(main_thread()); // Use main thread's resources read_uci_options(); } @@ -225,7 +219,6 @@ ThreadsManager::~ThreadsManager() { delete timer; lock_destroy(splitLock); cond_destroy(sleepCond); - tls_destroy(tlsKey); } @@ -314,13 +307,13 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta, assert(beta <= VALUE_INFINITE); assert(depth > DEPTH_ZERO); - Thread* master = this_thread(); + 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++]; + SplitPoint* sp = &master->splitPoints[master->splitPointsCnt]; sp->parent = master->curSplitPoint; sp->master = master; @@ -364,6 +357,8 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta, break; } + master->splitPointsCnt++; + lock_release(splitLock); lock_release(sp->lock);