mirror of
https://github.com/sockspls/badfish
synced 2025-07-13 12:39:16 +00:00
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 <mcostalba@gmail.com>
This commit is contained in:
parent
24b25b4827
commit
a189a5f0c5
4 changed files with 14 additions and 12 deletions
|
@ -20,9 +20,10 @@
|
||||||
#if !defined(HISTORY_H_INCLUDED)
|
#if !defined(HISTORY_H_INCLUDED)
|
||||||
#define HISTORY_H_INCLUDED
|
#define HISTORY_H_INCLUDED
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include <cstring>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
/// The History class stores statistics about how often different moves
|
/// The History class stores statistics about how often different moves
|
||||||
/// have been successful or unsuccessful during the current search. These
|
/// have been successful or unsuccessful during the current search. These
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#if !defined(LOCK_H_INCLUDED)
|
#if !defined(LOCK_H_INCLUDED)
|
||||||
#define LOCK_H_INCLUDED
|
#define LOCK_H_INCLUDED
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
|
|
||||||
|
@ -42,7 +42,10 @@ typedef pthread_t ThreadHandle;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if !defined(NOMINMAX)
|
||||||
# define NOMINMAX // disable macros min() and max()
|
# define NOMINMAX // disable macros min() and max()
|
||||||
|
#endif
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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 _CRT_SECURE_NO_DEPRECATE
|
||||||
#define NOMINMAX // disable macros min() and max()
|
#define NOMINMAX // disable macros min() and max()
|
||||||
|
@ -113,7 +113,7 @@ void dbg_print() {
|
||||||
|
|
||||||
int system_time() {
|
int system_time() {
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
struct _timeb t;
|
struct _timeb t;
|
||||||
_ftime(&t);
|
_ftime(&t);
|
||||||
return int(t.time * 1000 + t.millitm);
|
return int(t.time * 1000 + t.millitm);
|
||||||
|
@ -129,7 +129,7 @@ int system_time() {
|
||||||
|
|
||||||
int cpu_count() {
|
int cpu_count() {
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
SYSTEM_INFO s;
|
SYSTEM_INFO s;
|
||||||
GetSystemInfo(&s);
|
GetSystemInfo(&s);
|
||||||
return std::min(int(s.dwNumberOfProcessors), MAX_THREADS);
|
return std::min(int(s.dwNumberOfProcessors), MAX_THREADS);
|
||||||
|
@ -155,7 +155,7 @@ int cpu_count() {
|
||||||
|
|
||||||
void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
|
void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
int tm = msec;
|
int tm = msec;
|
||||||
#else
|
#else
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace { extern "C" {
|
||||||
// and last thread are special. First one is the main search thread while the
|
// 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().
|
// 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) {
|
DWORD WINAPI start_routine(LPVOID thread) {
|
||||||
#else
|
#else
|
||||||
void* start_routine(void* thread) {
|
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].do_sleep = (i != 0); // Avoid a race with start_thinking()
|
||||||
threads[i].threadID = i;
|
threads[i].threadID = i;
|
||||||
|
|
||||||
bool ok = thread_create(threads[i].handle, start_routine, threads[i]);
|
if (!thread_create(threads[i].handle, start_routine, threads[i]))
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to create thread number " << i << std::endl;
|
std::cerr << "Failed to create thread number " << i << std::endl;
|
||||||
::exit(EXIT_FAILURE);
|
::exit(EXIT_FAILURE);
|
||||||
|
|
Loading…
Add table
Reference in a new issue