1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
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>
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
35 #ifdef LOCALE_INVARIANT
36 #define MY_LOCALE LOCALE_INVARIANT
38 #define MY_LOCALE LOCALE_NEUTRAL
44 #include <sys/times.h>
54 void getWinProcTimes(double &rtime,
55 double &utime, double &stime,
56 double &cutime, double &cstime)
59 static const double ch = 4294967296.0e-7;
60 static const double cl = 1.0e-7;
63 GetSystemTimeAsFileTime(&system);
64 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
66 FILETIME create, exit, kernel, user;
67 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
68 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
69 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
82 rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
85 double tck=sysconf(_SC_CLK_TCK);
87 utime=ts.tms_utime/tck;
88 stime=ts.tms_stime/tck;
89 cutime=ts.tms_cutime/tck;
90 cstime=ts.tms_cstime/tck;
94 std::string getWinFormattedDate()
96 std::ostringstream os;
100 char buf1[11], buf2[9], buf3[5];
101 if (GetDateFormat(MY_LOCALE, 0, &time,
102 ("ddd MMM dd"), buf1, 11) &&
103 GetTimeFormat(MY_LOCALE, 0, &time,
104 ("HH':'mm':'ss"), buf2, 9) &&
105 GetDateFormat(MY_LOCALE, 0, &time,
106 ("yyyy"), buf3, 5)) {
107 os << buf1 << ' ' << buf2 << ' ' << buf3;
109 else os << "unknown";
112 gettimeofday(&tv, 0);
115 ctime_r(&tv.tv_sec,cbuf);
125 GetSystemTimeAsFileTime(&time);
126 return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
129 gettimeofday(&tv, 0);
130 return getpid() + tv.tv_sec + tv.tv_usec;
136 CRITICAL_SECTION *lock = new CRITICAL_SECTION;
137 InitializeCriticalSection(lock);
140 _repr = 0; //Just to avoid 'unused variable' warning with clang
144 WinLock::~WinLock() {
146 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
147 DeleteCriticalSection(lock);
152 void WinLock::lock() {
154 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
155 EnterCriticalSection(lock);
159 void WinLock::unlock() {
161 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
162 LeaveCriticalSection(lock);