From a189a5f0c53ec444652fdec78cff206279575bf8 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 25 Jan 2012 06:29:30 +0100 Subject: [PATCH] Use Windows threads library with mingw 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 --- src/history.h | 5 +++-- src/lock.h | 7 +++++-- src/misc.cpp | 8 ++++---- src/thread.cpp | 6 ++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/history.h b/src/history.h index 2eb93d85..7899c842 100644 --- a/src/history.h +++ b/src/history.h @@ -20,9 +20,10 @@ #if !defined(HISTORY_H_INCLUDED) #define HISTORY_H_INCLUDED -#include "types.h" -#include #include +#include + +#include "types.h" /// The History class stores statistics about how often different moves /// have been successful or unsuccessful during the current search. These diff --git a/src/lock.h b/src/lock.h index 44aeabd4..1e71305e 100644 --- a/src/lock.h +++ b/src/lock.h @@ -20,7 +20,7 @@ #if !defined(LOCK_H_INCLUDED) #define LOCK_H_INCLUDED -#if !defined(_MSC_VER) +#if !defined(_WIN32) && !defined(_WIN64) # include @@ -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 #undef WIN32_LEAN_AND_MEAN diff --git a/src/misc.cpp b/src/misc.cpp index ae8b6ffb..a3b1b032 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#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; diff --git a/src/thread.cpp b/src/thread.cpp index 2c40ef6f..81a718df 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -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); -- 2.39.2