]> git.sesse.net Git - stockfish/commitdiff
Destroy all locks before to exit
authorMarco Costalba <mcostalba@gmail.com>
Sun, 28 Feb 2010 11:23:53 +0000 (12:23 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 28 Feb 2010 22:36:02 +0000 (23:36 +0100)
And use platform-independent functions
where possible.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp

index eb038d0a8e507f8d8101cc4c1ef31c8de6d2685c..b3418b257351f6bbe051a913427c6357598b1e95 100644 (file)
@@ -94,11 +94,10 @@ namespace {
     Thread threads[MAX_THREADS];
     SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX];
 
     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;
 
 #if !defined(_MSC_VER)
     pthread_cond_t WaitCond;
-    pthread_mutex_t WaitLock;
 #else
     HANDLE SitIdleEvent[MAX_THREADS];
 #endif
 #else
     HANDLE SitIdleEvent[MAX_THREADS];
 #endif
@@ -2665,10 +2664,10 @@ namespace {
             threads[threadID].state = THREAD_SLEEPING;
 
 #if !defined(_MSC_VER)
             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);
             if (AllThreadsShouldSleep || threadID >= ActiveThreads)
                 pthread_cond_wait(&WaitCond, &WaitLock);
-            pthread_mutex_unlock(&WaitLock);
+            lock_release(&WaitLock);
 #else
             WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
 #endif
 #else
             WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
 #endif
@@ -2723,6 +2722,14 @@ namespace {
 
     // Initialize global locks
     lock_init(&MPLock, NULL);
 
     // 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++)
 
     // Initialize SplitPointStack locks
     for (i = 0; i < MAX_THREADS; i++)
@@ -2732,14 +2739,6 @@ namespace {
             lock_init(&(SplitPointStack[i][j].lock), NULL);
         }
 
             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;
 
     // Will be set just before program exits to properly end the threads
     AllThreadsShouldExit = false;
 
@@ -2794,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));
     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);
   }
 
 
   }