Fix wrong iteration in ListGraph snapshot, part II. (#598)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 ///\brief Some basic non-inline functions and static global data.
22 #include<lemon/bits/windows.h>
24 #if defined(LEMON_WIN32) && defined(__GNUC__)
25 #pragma GCC diagnostic ignored "-Wold-style-cast"
29 #ifndef WIN32_LEAN_AND_MEAN
30 #define WIN32_LEAN_AND_MEAN
39 #ifdef LOCALE_INVARIANT
40 #define MY_LOCALE LOCALE_INVARIANT
42 #define MY_LOCALE LOCALE_NEUTRAL
48 #include <sys/times.h>
58 void getWinProcTimes(double &rtime,
59 double &utime, double &stime,
60 double &cutime, double &cstime)
63 static const double ch = 4294967296.0e-7;
64 static const double cl = 1.0e-7;
67 GetSystemTimeAsFileTime(&system);
68 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
70 FILETIME create, exit, kernel, user;
71 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
72 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
73 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
86 rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
89 double tck=sysconf(_SC_CLK_TCK);
91 utime=ts.tms_utime/tck;
92 stime=ts.tms_stime/tck;
93 cutime=ts.tms_cutime/tck;
94 cstime=ts.tms_cstime/tck;
98 std::string getWinFormattedDate()
100 std::ostringstream os;
103 GetSystemTime(&time);
104 char buf1[11], buf2[9], buf3[5];
105 if (GetDateFormat(MY_LOCALE, 0, &time,
106 ("ddd MMM dd"), buf1, 11) &&
107 GetTimeFormat(MY_LOCALE, 0, &time,
108 ("HH':'mm':'ss"), buf2, 9) &&
109 GetDateFormat(MY_LOCALE, 0, &time,
110 ("yyyy"), buf3, 5)) {
111 os << buf1 << ' ' << buf2 << ' ' << buf3;
113 else os << "unknown";
116 gettimeofday(&tv, 0);
119 ctime_r(&tv.tv_sec,cbuf);
129 GetSystemTimeAsFileTime(&time);
130 return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
133 gettimeofday(&tv, 0);
134 return getpid() + tv.tv_sec + tv.tv_usec;
140 CRITICAL_SECTION *lock = new CRITICAL_SECTION;
141 InitializeCriticalSection(lock);
144 _repr = 0; //Just to avoid 'unused variable' warning with clang
148 WinLock::~WinLock() {
150 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
151 DeleteCriticalSection(lock);
156 void WinLock::lock() {
158 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
159 EnterCriticalSection(lock);
163 void WinLock::unlock() {
165 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
166 LeaveCriticalSection(lock);