2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 Alo Sarv <madcat_@users.sourceforge.net>
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2003 Timo Kujala <tiku@users.sourceforge.net>
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "GetTickCount.h" // Interface
31 void StartTickTimer(){};
33 void StopTickTimer(){};
35 uint32
GetTickCountFullRes() {
36 return GetTickCount();
40 * Returns the tickcount in 64bits.
42 uint64
GetTickCount64()
44 // The base value, can store more than 49 days worth of ms.
45 static uint64 tick
= 0;
46 // The current tickcount, may have overflown any number of times.
47 static uint32 lastTick
= 0;
49 uint32 curTick
= GetTickCount();
52 if ( curTick
< lastTick
) {
53 // Change the base value to contain the overflown value.
54 tick
+= (uint64
)1 << 32;
58 return tick
+ lastTick
;
63 #include <sys/time.h> // Needed for gettimeofday
65 uint32
GetTickCountFullRes(void) {
67 gettimeofday(&aika
,NULL
);
68 unsigned long msecs
= aika
.tv_sec
* 1000;
69 msecs
+= (aika
.tv_usec
/ 1000);
73 #if wxUSE_GUI && wxUSE_TIMER && !defined(AMULE_DAEMON)
75 * Copyright (c) 2004-2008 Alo Sarv <madcat_@users.sourceforge.net>
76 * wxTimer based implementation. wxGetLocalTimeMillis() is called every 2
77 * milliseconds and values stored in local variables. Upon requests for current
78 * time, values of those variables are returned. This means wxGetLocalTimeMillis
79 * is being called exactly 50 times per second at any case, no more no less.
83 class MyTimer
: public wxTimer
86 MyTimer() { tic32
= tic64
= wxGetLocalTimeMillis().GetValue(); Start(20); }
87 static uint32
GetTickCountNow() { return tic32
; }
88 static uint64
GetTickCountNow64() { return tic64
; }
90 void Notify() { tic32
= tic64
= wxGetLocalTimeMillis().GetValue(); }
96 static class MyTimer
* mytimer
;
98 // Initialization of the static MyTimer member variables.
99 uint32
MyTimer::tic32
= 0;
100 uint64
MyTimer::tic64
= 0;
102 void StartTickTimer() {
103 wxASSERT(mytimer
== NULL
);
104 mytimer
= new MyTimer();
107 void StopTickTimer() {
108 wxASSERT(mytimer
!= NULL
);
113 uint32
GetTickCount(){
114 wxASSERT(mytimer
!= NULL
);
115 return MyTimer::GetTickCountNow();
118 uint64
GetTickCount64(){
119 wxASSERT(mytimer
!= NULL
);
120 return MyTimer::GetTickCountNow64();
125 * Copyright (c) 2003-2008 Timo Kujala <tiku@users.sourceforge.net>
126 * gettimeofday() syscall based implementation. Upon request to GetTickCount(),
127 * gettimeofday syscall is being used to retrieve system time and returned. This
128 * means EACH GetTickCount() call will produce a new syscall, thus becoming
129 * increasingly heavy on CPU as the program uptime increases and more things
132 void StartTickTimer() {}
134 void StopTickTimer() {}
136 uint32
GetTickCount() { return GetTickCountFullRes(); }
138 // avoids 32bit rollover error for differences above 50days
139 uint64
GetTickCount64() {
141 gettimeofday(&aika
,NULL
);
142 return aika
.tv_sec
* 1000 + aika
.tv_usec
/ 1000;
148 // File_checked_for_headers