KiCad PCB EDA Suite
getrunningmicrosecs.cpp
Go to the documentation of this file.
1 
2 /*
3  * This program source code file is part of KiCad, a free EDA CAD application.
4  *
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 #include <config.h>
28 #include <common.h>
29 
30 #if defined(_WIN32)
31 
32 #define WIN32_LEAN_AND_MEAN 1
33 #include <windows.h>
34 
35 unsigned GetRunningMicroSecs()
36 {
37  FILETIME now;
38 
39  GetSystemTimeAsFileTime( &now );
40  unsigned long long t = (UINT64(now.dwHighDateTime) << 32) + now.dwLowDateTime;
41  t /= 10;
42 
43  return unsigned( t );
44 }
45 
46 #elif defined(HAVE_CLOCK_GETTIME)
47 
48 #include <time.h>
49 
50 unsigned GetRunningMicroSecs()
51 {
52  struct timespec now;
53 
54  clock_gettime( CLOCK_MONOTONIC, &now );
55 
56  unsigned usecs = ((unsigned)now.tv_nsec)/1000 + ((unsigned)now.tv_sec) * 1000000;
57 // unsigned msecs = (now.tv_nsec / (1000*1000)) + now.tv_sec * 1000;
58 
59  return usecs;
60 }
61 
62 
63 #elif defined(HAVE_GETTIMEOFDAY_FUNC)
64 
65 #include <sys/time.h>
66 unsigned GetRunningMicroSecs()
67 {
68  timeval tv;
69 
70  gettimeofday( &tv, 0 );
71 
72  return (tv.tv_sec * 1000000) + tv.tv_usec;
73 }
74 
75 #endif
76 
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
The common library.