1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Move sleepLock and sleepCond under Thread

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-04-19 09:56:59 +02:00
parent 2e6839c9a0
commit fdc9f8cbd7
2 changed files with 14 additions and 13 deletions

View file

@ -83,14 +83,13 @@ namespace {
Depth depth, Move threatMove, int moveCount, MovePicker* mp, bool pvNode); Depth depth, Move threatMove, int moveCount, MovePicker* mp, bool pvNode);
private: private:
Lock mpLock;
Depth minimumSplitDepth; Depth minimumSplitDepth;
int maxThreadsPerSplitPoint; int maxThreadsPerSplitPoint;
bool useSleepingThreads; bool useSleepingThreads;
int activeThreads; int activeThreads;
volatile bool allThreadsShouldExit; volatile bool allThreadsShouldExit;
Thread threads[MAX_THREADS]; Thread threads[MAX_THREADS];
Lock mpLock, sleepLock[MAX_THREADS];
WaitCondition sleepCond[MAX_THREADS];
}; };
@ -2047,7 +2046,7 @@ split_point_start: // At split points actual search starts from here
threads[threadID].state = THREAD_AVAILABLE; threads[threadID].state = THREAD_AVAILABLE;
// Grab the lock to avoid races with wake_sleeping_thread() // Grab the lock to avoid races with wake_sleeping_thread()
lock_grab(&sleepLock[threadID]); lock_grab(&threads[threadID].sleepLock);
// If we are master and all slaves have finished do not go to sleep // If we are master and all slaves have finished do not go to sleep
for (i = 0; sp && i < activeThreads && !sp->slaves[i]; i++) {} for (i = 0; sp && i < activeThreads && !sp->slaves[i]; i++) {}
@ -2055,15 +2054,15 @@ split_point_start: // At split points actual search starts from here
if (allFinished || allThreadsShouldExit) if (allFinished || allThreadsShouldExit)
{ {
lock_release(&sleepLock[threadID]); lock_release(&threads[threadID].sleepLock);
break; break;
} }
// Do sleep here after retesting sleep conditions // Do sleep here after retesting sleep conditions
if (threadID >= activeThreads || threads[threadID].state == THREAD_AVAILABLE) if (threadID >= activeThreads || threads[threadID].state == THREAD_AVAILABLE)
cond_wait(&sleepCond[threadID], &sleepLock[threadID]); cond_wait(&threads[threadID].sleepCond, &threads[threadID].sleepLock);
lock_release(&sleepLock[threadID]); lock_release(&threads[threadID].sleepLock);
} }
// If this thread has been assigned work, launch a search // If this thread has been assigned work, launch a search
@ -2134,8 +2133,8 @@ split_point_start: // At split points actual search starts from here
for (i = 0; i < MAX_THREADS; i++) for (i = 0; i < MAX_THREADS; i++)
{ {
lock_init(&sleepLock[i]); lock_init(&threads[i].sleepLock);
cond_init(&sleepCond[i]); cond_init(&threads[i].sleepCond);
} }
// Initialize splitPoints[] locks // Initialize splitPoints[] locks
@ -2202,8 +2201,8 @@ split_point_start: // At split points actual search starts from here
// Now we can safely destroy the wait conditions // Now we can safely destroy the wait conditions
for (int i = 0; i < MAX_THREADS; i++) for (int i = 0; i < MAX_THREADS; i++)
{ {
lock_destroy(&sleepLock[i]); lock_destroy(&threads[i].sleepLock);
cond_destroy(&sleepCond[i]); cond_destroy(&threads[i].sleepCond);
} }
} }
@ -2392,9 +2391,9 @@ split_point_start: // At split points actual search starts from here
void ThreadsManager::wake_sleeping_thread(int threadID) { void ThreadsManager::wake_sleeping_thread(int threadID) {
lock_grab(&sleepLock[threadID]); lock_grab(&threads[threadID].sleepLock);
cond_signal(&sleepCond[threadID]); cond_signal(&threads[threadID].sleepCond);
lock_release(&sleepLock[threadID]); lock_release(&threads[threadID].sleepLock);
} }

View file

@ -68,6 +68,8 @@ enum ThreadState
}; };
struct Thread { struct Thread {
Lock sleepLock;
WaitCondition sleepCond;
volatile ThreadState state; volatile ThreadState state;
SplitPoint* volatile splitPoint; SplitPoint* volatile splitPoint;
volatile int activeSplitPoints; volatile int activeSplitPoints;