X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=b3418b257351f6bbe051a913427c6357598b1e95;hp=c369bac3a98d0f64c2336f3cab725e380bc384ed;hb=0f50f10327bc1a53d656d5d8c918a9ee413e5e84;hpb=14dbeb22dd04f0954322a58c26833506fb4532a9 diff --git a/src/search.cpp b/src/search.cpp index c369bac3..b3418b25 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -94,11 +94,10 @@ namespace { Thread threads[MAX_THREADS]; SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX]; - Lock MPLock; + Lock MPLock, WaitLock; #if !defined(_MSC_VER) pthread_cond_t WaitCond; - pthread_mutex_t WaitLock; #else HANDLE SitIdleEvent[MAX_THREADS]; #endif @@ -2593,7 +2592,7 @@ namespace { DWORD WINAPI init_thread(LPVOID threadID) { TM.idle_loop(*(int*)threadID, NULL); - return NULL; + return 0; } #endif @@ -2665,10 +2664,10 @@ namespace { threads[threadID].state = THREAD_SLEEPING; #if !defined(_MSC_VER) - pthread_mutex_lock(&WaitLock); + lock_grab(&WaitLock); if (AllThreadsShouldSleep || threadID >= ActiveThreads) pthread_cond_wait(&WaitCond, &WaitLock); - pthread_mutex_unlock(&WaitLock); + lock_release(&WaitLock); #else WaitForSingleObject(SitIdleEvent[threadID], INFINITE); #endif @@ -2723,6 +2722,14 @@ namespace { // Initialize global locks lock_init(&MPLock, NULL); + lock_init(&WaitLock, NULL); + +#if !defined(_MSC_VER) + pthread_cond_init(&WaitCond, NULL); +#else + for (i = 0; i < MAX_THREADS; i++) + SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0); +#endif // Initialize SplitPointStack locks for (i = 0; i < MAX_THREADS; i++) @@ -2732,14 +2739,6 @@ namespace { lock_init(&(SplitPointStack[i][j].lock), NULL); } -#if !defined(_MSC_VER) - pthread_mutex_init(&WaitLock, NULL); - pthread_cond_init(&WaitCond, NULL); -#else - for (i = 0; i < MAX_THREADS; i++) - SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0); -#endif - // Will be set just before program exits to properly end the threads AllThreadsShouldExit = false; @@ -2759,8 +2758,7 @@ namespace { #if !defined(_MSC_VER) ok = (pthread_create(pthread, NULL, init_thread, (void*)(&i)) == 0); #else - DWORD iID[1]; - ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID) != NULL); + ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, NULL) != NULL); #endif if (!ok) @@ -2795,6 +2793,9 @@ namespace { for (int i = 0; i < MAX_THREADS; i++) for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++) lock_destroy(&(SplitPointStack[i][j].lock)); + + lock_destroy(&WaitLock); + lock_destroy(&MPLock); }