summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-01-06 18:46:17 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-01-06 18:46:17 +0000
commit383339dedf6f1a52b8d6b0196068232daec83526 (patch)
treefe8bca4bc6b45e83d5c8e70a2ff1e1af4d1b99ae /src/utils
parent593e65eef0d43f2ff61dc1b4f3160c0a16b5f015 (diff)
downloadmanaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.gz
manaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.bz2
manaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.xz
manaserv-383339dedf6f1a52b8d6b0196068232daec83526.zip
Removed world timer usage from account server, instead letting ENet wait during
each host service to reduce CPU usage. Modified timer code to gracefully handle jumps back in time.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/timer.cpp22
-rw-r--r--src/utils/timer.h6
2 files changed, 19 insertions, 9 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index b0a05bc5..a1d8bd46 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -19,9 +19,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <time.h>
#include "timer.h"
+#include <time.h>
+#include <sys/time.h>
+
+#ifdef _WIN32
+#include "wingettimeofday.h"
+#endif
+
namespace utils
{
@@ -52,8 +58,18 @@ int Timer::poll()
int elapsed = 0;
if (active)
{
- elapsed = (getTimeInMillisec() - lastpulse) / interval;
- lastpulse += interval * elapsed;
+ uint64_t now = getTimeInMillisec();
+ if (now > lastpulse)
+ {
+ elapsed = (now - lastpulse) / interval;
+ lastpulse += interval * elapsed;
+ }
+ else
+ {
+ // Time has made a jump to the past. This should be a rare
+ // occurence, so just reset lastpulse to prevent problems.
+ lastpulse = now;
+ }
};
return elapsed;
}
diff --git a/src/utils/timer.h b/src/utils/timer.h
index 69ca634e..da3a1d07 100644
--- a/src/utils/timer.h
+++ b/src/utils/timer.h
@@ -22,8 +22,6 @@
#ifndef _TMWSERV_TIMER_H_
#define _TMWSERV_TIMER_H_
-#include <sys/time.h>
-
/* I need a 64-bit unsigned integer */
#ifdef _MSC_VER
typedef __uint64 uint64_t // when using MSVC use its internal type
@@ -31,10 +29,6 @@
#include <stdint.h> // on other compilers use the C99 official header
#endif
-#ifdef _WIN32
- #include "wingettimeofday.h"
-#endif
-
namespace utils
{