1.1 --- a/lemon/bits/windows.cc Mon Jul 16 16:21:40 2018 +0200
1.2 +++ b/lemon/bits/windows.cc Wed Oct 17 19:14:07 2018 +0200
1.3 @@ -2,7 +2,7 @@
1.4 *
1.5 * This file is a part of LEMON, a generic C++ optimization library.
1.6 *
1.7 - * Copyright (C) 2003-2010
1.8 + * Copyright (C) 2003-2013
1.9 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 *
1.12 @@ -21,7 +21,11 @@
1.13
1.14 #include<lemon/bits/windows.h>
1.15
1.16 -#ifdef WIN32
1.17 +#if defined(LEMON_WIN32) && defined(__GNUC__)
1.18 +#pragma GCC diagnostic ignored "-Wold-style-cast"
1.19 +#endif
1.20 +
1.21 +#ifdef LEMON_WIN32
1.22 #ifndef WIN32_LEAN_AND_MEAN
1.23 #define WIN32_LEAN_AND_MEAN
1.24 #endif
1.25 @@ -40,7 +44,7 @@
1.26 #else
1.27 #include <unistd.h>
1.28 #include <ctime>
1.29 -#ifndef WIN32
1.30 +#ifndef LEMON_WIN32
1.31 #include <sys/times.h>
1.32 #endif
1.33 #include <sys/time.h>
1.34 @@ -55,7 +59,7 @@
1.35 double &utime, double &stime,
1.36 double &cutime, double &cstime)
1.37 {
1.38 -#ifdef WIN32
1.39 +#ifdef LEMON_WIN32
1.40 static const double ch = 4294967296.0e-7;
1.41 static const double cl = 1.0e-7;
1.42
1.43 @@ -94,11 +98,11 @@
1.44 std::string getWinFormattedDate()
1.45 {
1.46 std::ostringstream os;
1.47 -#ifdef WIN32
1.48 +#ifdef LEMON_WIN32
1.49 SYSTEMTIME time;
1.50 GetSystemTime(&time);
1.51 char buf1[11], buf2[9], buf3[5];
1.52 - if (GetDateFormat(MY_LOCALE, 0, &time,
1.53 + if (GetDateFormat(MY_LOCALE, 0, &time,
1.54 ("ddd MMM dd"), buf1, 11) &&
1.55 GetTimeFormat(MY_LOCALE, 0, &time,
1.56 ("HH':'mm':'ss"), buf2, 9) &&
1.57 @@ -120,7 +124,7 @@
1.58
1.59 int getWinRndSeed()
1.60 {
1.61 -#ifdef WIN32
1.62 +#ifdef LEMON_WIN32
1.63 FILETIME time;
1.64 GetSystemTimeAsFileTime(&time);
1.65 return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
1.66 @@ -130,5 +134,37 @@
1.67 return getpid() + tv.tv_sec + tv.tv_usec;
1.68 #endif
1.69 }
1.70 +
1.71 + WinLock::WinLock() {
1.72 +#ifdef LEMON_WIN32
1.73 + CRITICAL_SECTION *lock = new CRITICAL_SECTION;
1.74 + InitializeCriticalSection(lock);
1.75 + _repr = lock;
1.76 +#else
1.77 + _repr = 0; //Just to avoid 'unused variable' warning with clang
1.78 +#endif
1.79 + }
1.80 +
1.81 + WinLock::~WinLock() {
1.82 +#ifdef LEMON_WIN32
1.83 + CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
1.84 + DeleteCriticalSection(lock);
1.85 + delete lock;
1.86 +#endif
1.87 + }
1.88 +
1.89 + void WinLock::lock() {
1.90 +#ifdef LEMON_WIN32
1.91 + CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
1.92 + EnterCriticalSection(lock);
1.93 +#endif
1.94 + }
1.95 +
1.96 + void WinLock::unlock() {
1.97 +#ifdef LEMON_WIN32
1.98 + CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
1.99 + LeaveCriticalSection(lock);
1.100 +#endif
1.101 + }
1.102 }
1.103 }