]> git.sesse.net Git - stockfish/commitdiff
Use Windows threads library with mingw
authorMarco Costalba <mcostalba@gmail.com>
Wed, 25 Jan 2012 05:29:30 +0000 (06:29 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 25 Jan 2012 06:32:31 +0000 (07:32 +0100)
Instead of Posix threads. This seems to fix time
losses of the gcc compiled version for Windows.
The patch replaces the MSVC specific _MSC_VER flag
with _WIN32 and _WIN64 that are defined both by
MSVC and mingw-gcc.

Workaround found by Jim Ablett.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/history.h
src/lock.h
src/misc.cpp
src/thread.cpp

index 2eb93d85926045632dc8b7f0211565e74f56715a..7899c842ae99b54fc0b4552639631c317413b4df 100644 (file)
 #if !defined(HISTORY_H_INCLUDED)
 #define HISTORY_H_INCLUDED
 
-#include "types.h"
-#include <cstring>
 #include <algorithm>
+#include <cstring>
+
+#include "types.h"
 
 /// The History class stores statistics about how often different moves
 /// have been successful or unsuccessful during the current search. These
index 44aeabd4771139e371c95db0f7a6e1da1957d636..1e71305ec1c7403bbcbebe538d50e6e135ddc9bc 100644 (file)
@@ -20,7 +20,7 @@
 #if !defined(LOCK_H_INCLUDED)
 #define LOCK_H_INCLUDED
 
-#if !defined(_MSC_VER)
+#if !defined(_WIN32) && !defined(_WIN64)
 
 #  include <pthread.h>
 
@@ -42,7 +42,10 @@ typedef pthread_t ThreadHandle;
 
 #else
 
-#define NOMINMAX // disable macros min() and max()
+#if !defined(NOMINMAX)
+#  define NOMINMAX // disable macros min() and max()
+#endif
+
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #undef WIN32_LEAN_AND_MEAN
index ae8b6ffbed302c7e0075d5ddfe29a9fcd3ecc4b9..a3b1b0324c8ee20357fb515294696d9b9befb240 100644 (file)
@@ -17,7 +17,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#if defined(_MSC_VER)
+#if defined(_WIN32) || defined(_WIN64)
 
 #define _CRT_SECURE_NO_DEPRECATE
 #define NOMINMAX // disable macros min() and max()
@@ -113,7 +113,7 @@ void dbg_print() {
 
 int system_time() {
 
-#if defined(_MSC_VER)
+#if defined(_WIN32) || defined(_WIN64)
   struct _timeb t;
   _ftime(&t);
   return int(t.time * 1000 + t.millitm);
@@ -129,7 +129,7 @@ int system_time() {
 
 int cpu_count() {
 
-#if defined(_MSC_VER)
+#if defined(_WIN32) || defined(_WIN64)
   SYSTEM_INFO s;
   GetSystemInfo(&s);
   return std::min(int(s.dwNumberOfProcessors), MAX_THREADS);
@@ -155,7 +155,7 @@ int cpu_count() {
 
 void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
 
-#if defined(_MSC_VER)
+#if defined(_WIN32) || defined(_WIN64)
   int tm = msec;
 #else
   struct timeval t;
index 2c40ef6f8c14ecc7ccc218a01d06dada354d8874..81a718df8a0ff8e691cc7431736c2fd34378cb0d 100644 (file)
@@ -36,7 +36,7 @@ namespace { extern "C" {
  // and last thread are special. First one is the main search thread while the
  // last one mimics a timer, they run in main_loop() and timer_loop().
 
-#if defined(_MSC_VER)
+#if defined(_WIN32) || defined(_WIN64)
   DWORD WINAPI start_routine(LPVOID thread) {
 #else
   void* start_routine(void* thread) {
@@ -177,9 +177,7 @@ void ThreadsManager::init() {
       threads[i].do_sleep = (i != 0); // Avoid a race with start_thinking()
       threads[i].threadID = i;
 
-      bool ok = thread_create(threads[i].handle, start_routine, threads[i]);
-
-      if (!ok)
+      if (!thread_create(threads[i].handle, start_routine, threads[i]))
       {
           std::cerr << "Failed to create thread number " << i << std::endl;
           ::exit(EXIT_FAILURE);