summaryrefslogtreecommitdiff
path: root/src/common/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/timer.c')
-rw-r--r--src/common/timer.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/common/timer.c b/src/common/timer.c
index 526854582..370eafd4c 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -2,11 +2,8 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/cbasetypes.h"
-#include "../common/db.h"
-#include "../common/malloc.h"
-#include "../common/showmsg.h"
-#include "../common/utils.h"
+#define HERCULES_CORE
+
#include "timer.h"
#include <stdio.h>
@@ -14,11 +11,17 @@
#include <string.h>
#include <time.h>
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/showmsg.h"
+#include "../common/utils.h"
+
#ifdef WIN32
-#include "../common/winapi.h" // GetTickCount()
+# include "../common/winapi.h" // GetTickCount()
#else
-#include <unistd.h>
-#include <sys/time.h> // struct timeval, gettimeofday()
+# include <sys/time.h> // struct timeval, gettimeofday()
+# include <unistd.h>
#endif
struct timer_interface timer_s;
@@ -104,7 +107,7 @@ char* search_timer_func_list(TimerFunc func)
#if defined(ENABLE_RDTSC)
static uint64 RDTSC_BEGINTICK = 0, RDTSC_CLOCK = 0;
-static __inline uint64 _rdtsc(){
+static __inline uint64 rdtsc_(void) {
register union{
uint64 qw;
uint32 dw[2];
@@ -115,7 +118,7 @@ static __inline uint64 _rdtsc(){
return t.qw;
}
-static void rdtsc_calibrate(){
+static void rdtsc_calibrate(void){
uint64 t1, t2;
int32 i;
@@ -124,14 +127,14 @@ static void rdtsc_calibrate(){
RDTSC_CLOCK = 0;
for(i = 0; i < 5; i++){
- t1 = _rdtsc();
+ t1 = rdtsc_();
usleep(1000000); //1000 MS
- t2 = _rdtsc();
- RDTSC_CLOCK += (t2 - t1) / 1000;
+ t2 = rdtsc_();
+ RDTSC_CLOCK += (t2 - t1) / 1000;
}
RDTSC_CLOCK /= 5;
- RDTSC_BEGINTICK = _rdtsc();
+ RDTSC_BEGINTICK = rdtsc_();
ShowMessage(" done. (Frequency: %u Mhz)\n", (uint32)(RDTSC_CLOCK/1000) );
}
@@ -167,17 +170,17 @@ static int64 sys_tick(void) {
}
if (pGetTickCount64)
return (int64)pGetTickCount64();
- // 32-bit fallback. Note: This will wrap around every ~49 days since system startup!!!
+ // 32-bit fall back. Note: This will wrap around every ~49 days since system startup!!!
return (int64)GetTickCount();
#elif defined(ENABLE_RDTSC)
// RDTSC: Returns the number of CPU cycles since reset. Unreliable if
// the CPU frequency is variable.
- return (int64)((_rdtsc() - RDTSC_BEGINTICK) / RDTSC_CLOCK);
+ return (int64)((rdtsc_() - RDTSC_BEGINTICK) / RDTSC_CLOCK);
#elif defined(HAVE_MONOTONIC_CLOCK)
- // Monotinic clock: Implementation-defined.
+ // Monotonic clock: Implementation-defined.
// Clock that cannot be set and represents monotonic time since some
// unspecified starting point. This clock is not affected by
- // discontin‐uous jumps in the system time (e.g., if the system
+ // discontinuous jumps in the system time (e.g., if the system
// administrator manually changes the clock), but is affected by
// the incremental adjustments performed by adjtime(3) and NTP.
struct timespec tval;
@@ -185,7 +188,7 @@ static int64 sys_tick(void) {
// int64 cast to avoid overflows on platforms where time_t is 32 bit
return (int64)tval.tv_sec * 1000 + tval.tv_nsec / 1000000;
#else
- // Fallback, regular clock: Number of milliseconds since epoch.
+ // Fall back, regular clock: Number of milliseconds since epoch.
// The time returned by gettimeofday() is affected by discontinuous
// jumps in the system time (e.g., if the system administrator
// manually changes the system time). If you need a monotonically
@@ -450,7 +453,7 @@ void timer_final(void) {
if (free_timer_list) aFree(free_timer_list);
}
/*=====================================
-* Default Functions : timer.h
+* Default Functions : timer.h
* Generated by HerculesInterfaceMaker
* created by Susu
*-------------------------------------*/