summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-25 08:50:52 -0300
committershennetsind <ind@henn.et>2013-09-25 08:50:52 -0300
commit1114eb3da58b078258a824424fef687a1ccee90c (patch)
tree1b9c3e4ef48021ce89b331bba2d49061bd08f341 /src/common
parent78c7c6bf04a6c96d92524ae37ad165e65f599eb8 (diff)
downloadhercules-1114eb3da58b078258a824424fef687a1ccee90c.tar.gz
hercules-1114eb3da58b078258a824424fef687a1ccee90c.tar.bz2
hercules-1114eb3da58b078258a824424fef687a1ccee90c.tar.xz
hercules-1114eb3da58b078258a824424fef687a1ccee90c.zip
Renamed iTimer interface to timer.
Also removed duplicate mentions of timer within calls to shorten.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c2
-rw-r--r--src/common/console.c6
-rw-r--r--src/common/core.c6
-rw-r--r--src/common/mutex.c2
-rw-r--r--src/common/random.c2
-rw-r--r--src/common/socket.c12
-rw-r--r--src/common/sql.c4
-rw-r--r--src/common/timer.c34
-rw-r--r--src/common/timer.h18
9 files changed, 44 insertions, 42 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 3b79febd7..9895ae95d 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -470,7 +470,7 @@ void hplugins_share_defaults(void) {
/* sql */
HPM->share(SQL,"SQL");
/* timer */
- HPM->share(iTimer,"iTimer");
+ HPM->share(timer,"timer");
}
diff --git a/src/common/console.c b/src/common/console.c
index c9772ecfd..75b6eaea4 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -362,7 +362,7 @@ void console_parse_final(void) {
/* wait for thread to close */
rathread_wait(console->pthread, NULL);
-
+
racond_destroy(console->ptcond);
ramutex_destroy(console->ptmutex);
}
@@ -382,8 +382,8 @@ void console_parse_init(void) {
exit(EXIT_FAILURE);
}
- iTimer->add_timer_func_list(console->parse_timer, "console_parse_timer");
- iTimer->add_timer_interval(iTimer->gettick() + 1000, console->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */
+ timer->add_func_list(console->parse_timer, "console_parse_timer");
+ timer->add_interval(timer->gettick() + 1000, console->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */
}
void console_setSQL(Sql *SQL) {
diff --git a/src/common/core.c b/src/common/core.c
index 1e5179448..6a73d2d39 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -325,7 +325,7 @@ int main (int argc, char **argv) {
cevents_init();
#endif
- iTimer->init();
+ timer->init();
console->init();
@@ -341,7 +341,7 @@ int main (int argc, char **argv) {
{// Main runtime cycle
int next;
while (runflag != CORE_ST_STOP) {
- next = iTimer->do_timer(iTimer->gettick_nocache());
+ next = timer->do_timer(timer->gettick_nocache());
do_sockets(next);
}
}
@@ -352,7 +352,7 @@ int main (int argc, char **argv) {
#ifndef MINICORE
HPM->final();
#endif
- iTimer->final();
+ timer->final();
socket_final();
DB->final();
mempool_final();
diff --git a/src/common/mutex.c b/src/common/mutex.c
index 6bb1efdab..0668dbc41 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -201,7 +201,7 @@ void racond_wait( racond c, ramutex m, sysint timeout_ticks){
pthread_cond_wait( &c->hCond, &m->hMutex );
}else{
struct timespec wtime;
- int64 exact_timeout = iTimer->gettick() + timeout_ticks;
+ int64 exact_timeout = timer->gettick() + timeout_ticks;
wtime.tv_sec = exact_timeout/1000;
wtime.tv_nsec = (exact_timeout%1000)*1000000;
diff --git a/src/common/random.c b/src/common/random.c
index a7d432e34..2f1b62934 100644
--- a/src/common/random.c
+++ b/src/common/random.c
@@ -17,7 +17,7 @@
/// Initializes the random number generator with an appropriate seed.
void rnd_init(void)
{
- uint32 seed = iTimer->gettick();
+ uint32 seed = timer->gettick();
seed += (uint32)time(NULL);
#if defined(WIN32)
seed += GetCurrentProcessId();
diff --git a/src/common/socket.c b/src/common/socket.c
index 4f2e386ec..7c8b3738b 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1012,9 +1012,9 @@ static int connect_check_(uint32 ip)
if( hist->ddos )
{// flagged as DDoS
return (connect_ok == 2 ? 1 : 0);
- } else if( DIFF_TICK(iTimer->gettick(),hist->tick) < ddos_interval )
+ } else if( DIFF_TICK(timer->gettick(),hist->tick) < ddos_interval )
{// connection within ddos_interval
- hist->tick = iTimer->gettick();
+ hist->tick = timer->gettick();
if( hist->count++ >= ddos_count )
{// DDoS attack detected
hist->ddos = 1;
@@ -1024,7 +1024,7 @@ static int connect_check_(uint32 ip)
return connect_ok;
} else
{// not within ddos_interval, clear data
- hist->tick = iTimer->gettick();
+ hist->tick = timer->gettick();
hist->count = 0;
return connect_ok;
}
@@ -1035,7 +1035,7 @@ static int connect_check_(uint32 ip)
CREATE(hist, ConnectHistory, 1);
memset(hist, 0, sizeof(ConnectHistory));
hist->ip = ip;
- hist->tick = iTimer->gettick();
+ hist->tick = timer->gettick();
hist->next = connect_history[ip&0xFFFF];
connect_history[ip&0xFFFF] = hist;
return connect_ok;
@@ -1400,8 +1400,8 @@ void socket_init(void)
#ifndef MINICORE
// Delete old connection history every 5 minutes
memset(connect_history, 0, sizeof(connect_history));
- iTimer->add_timer_func_list(connect_check_clear, "connect_check_clear");
- iTimer->add_timer_interval(iTimer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000);
+ timer->add_func_list(connect_check_clear, "connect_check_clear");
+ timer->add_interval(timer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000);
#endif
ShowInfo("Server supports up to '"CL_WHITE"%u"CL_RESET"' concurrent connections.\n", rlim_cur);
diff --git a/src/common/sql.c b/src/common/sql.c
index 579346001..9b7fe4108 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -210,7 +210,7 @@ static int Sql_P_Keepalive(Sql* self)
// establish keepalive
ping_interval = timeout - 30; // 30-second reserve
//add_timer_func_list(Sql_P_KeepaliveTimer, "Sql_P_KeepaliveTimer");
- return iTimer->add_timer_interval(iTimer->gettick() + ping_interval*1000, Sql_P_KeepaliveTimer, 0, (intptr_t)self, ping_interval*1000);
+ return timer->add_interval(timer->gettick() + ping_interval*1000, Sql_P_KeepaliveTimer, 0, (intptr_t)self, ping_interval*1000);
}
@@ -404,7 +404,7 @@ void Sql_Free(Sql* self)
{
SQL->FreeResult(self);
StrBuf->Destroy(&self->buf);
- if( self->keepalive != INVALID_TIMER ) iTimer->delete_timer(self->keepalive, Sql_P_KeepaliveTimer);
+ if( self->keepalive != INVALID_TIMER ) timer->delete(self->keepalive, Sql_P_KeepaliveTimer);
aFree(self);
}
}
diff --git a/src/common/timer.c b/src/common/timer.c
index f019c6927..a2378a5aa 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -21,6 +21,8 @@
#include <sys/time.h> // struct timeval, gettimeofday()
#endif
+struct timer_interface timer_s;
+
// If the server can't handle processing thousands of monsters
// or many connected clients, please increase TIMER_MIN_INTERVAL.
#define TIMER_MIN_INTERVAL 50
@@ -257,7 +259,7 @@ int timer_add_interval(unsigned int tick, TimerFunc func, int id, intptr_t data,
int tid;
if( interval < 1 ) {
- ShowError("timer_add_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, iTimer->gettick()));
+ ShowError("timer_add_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, timer->gettick()));
return INVALID_TIMER;
}
@@ -300,7 +302,7 @@ int timer_do_delete(int tid, TimerFunc func) {
/// Adjusts a timer's expiration time.
/// Returns the new tick value, or -1 if it fails.
int timer_addtick(int tid, unsigned int tick) {
- return iTimer->settick_timer(tid, timer_data[tid].tick+tick);
+ return timer->settick(tid, timer_data[tid].tick+tick);
}
/// Modifies a timer's expiration time (an alternative to deleting a timer and starting a new one).
@@ -415,20 +417,20 @@ void timer_final(void) {
* created by Susu
*-------------------------------------*/
void timer_defaults(void) {
- iTimer = &iTimer_s;
+ timer = &timer_s;
/* funcs */
- iTimer->gettick = timer_gettick;
- iTimer->gettick_nocache = timer_gettick_nocache;
- iTimer->add_timer = timer_add;
- iTimer->add_timer_interval = timer_add_interval;
- iTimer->add_timer_func_list = timer_add_func_list;
- iTimer->get_timer = timer_get;
- iTimer->delete_timer = timer_do_delete;
- iTimer->addtick_timer = timer_addtick;
- iTimer->settick_timer = timer_settick;
- iTimer->get_uptime = timer_get_uptime;
- iTimer->do_timer = do_timer;
- iTimer->init = timer_init;
- iTimer->final = timer_final;
+ timer->gettick = timer_gettick;
+ timer->gettick_nocache = timer_gettick_nocache;
+ timer->add = timer_add;
+ timer->add_interval = timer_add_interval;
+ timer->add_func_list = timer_add_func_list;
+ timer->get = timer_get;
+ timer->delete = timer_do_delete;
+ timer->addtick = timer_addtick;
+ timer->settick = timer_settick;
+ timer->get_uptime = timer_get_uptime;
+ timer->do_timer = do_timer;
+ timer->init = timer_init;
+ timer->final = timer_final;
}
diff --git a/src/common/timer.h b/src/common/timer.h
index 50f1c354b..3146a2e66 100644
--- a/src/common/timer.h
+++ b/src/common/timer.h
@@ -44,24 +44,24 @@ struct timer_interface {
unsigned int (*gettick) (void);
unsigned int (*gettick_nocache) (void);
- int (*add_timer) (unsigned int tick, TimerFunc func, int id, intptr_t data);
- int (*add_timer_interval) (unsigned int tick, TimerFunc func, int id, intptr_t data, int interval);
- const struct TimerData *(*get_timer) (int tid);
- int (*delete_timer) (int tid, TimerFunc func);
+ int (*add) (unsigned int tick, TimerFunc func, int id, intptr_t data);
+ int (*add_interval) (unsigned int tick, TimerFunc func, int id, intptr_t data, int interval);
+ const struct TimerData *(*get) (int tid);
+ int (*delete) (int tid, TimerFunc func);
- int (*addtick_timer) (int tid, unsigned int tick);
- int (*settick_timer) (int tid, unsigned int tick);
+ int (*addtick) (int tid, unsigned int tick);
+ int (*settick) (int tid, unsigned int tick);
- int (*add_timer_func_list) (TimerFunc func, char* name);
+ int (*add_func_list) (TimerFunc func, char* name);
unsigned long (*get_uptime) (void);
int (*do_timer) (unsigned int tick);
void (*init) (void);
void (*final) (void);
-} iTimer_s;
+};
-struct timer_interface *iTimer;
+struct timer_interface *timer;
void timer_defaults(void);