diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-11 16:11:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-11 16:11:43 +0300 |
commit | 6c0f05b05e9bf09f40df3e3fe7f768f7435abcec (patch) | |
tree | 6973517e1821f128b36955fc258419131b98f7fc /src/common/timer.c | |
parent | d70d9d4d19f0deae2a2aceb047872611d5047ae0 (diff) | |
parent | 845139091f0305d264800491ce25152856c20374 (diff) | |
download | hercules-6c0f05b05e9bf09f40df3e3fe7f768f7435abcec.tar.gz hercules-6c0f05b05e9bf09f40df3e3fe7f768f7435abcec.tar.bz2 hercules-6c0f05b05e9bf09f40df3e3fe7f768f7435abcec.tar.xz hercules-6c0f05b05e9bf09f40df3e3fe7f768f7435abcec.zip |
Merge pull request #760 from HerculesWS/738-vectors
Change several variable-size array to VECTOR (common, char)
Diffstat (limited to 'src/common/timer.c')
-rw-r--r-- | src/common/timer.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/common/timer.c b/src/common/timer.c index 793706511..f6ce00d54 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -239,6 +239,10 @@ int64 timer_gettick(void) { /// Adds a timer to the timer_heap static void push_timer_heap(int tid) { BHEAP_ENSURE(timer_heap, 1, 256); +#ifdef __clang_analyzer__ // Clang's static analyzer warns that BHEAP_ENSURE might set BHEAP_DATA(timer_heap) to NULL. +#include "assert.h" + assert(BHEAP_DATA(timer_heap) != NULL); +#endif // __clang_analyzer__ BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, swap); } @@ -348,14 +352,21 @@ int64 timer_addtick(int tid, int64 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). -/// Returns the new tick value, or -1 if it fails. -int64 timer_settick(int tid, int64 tick) { - size_t i; +/** + * Modifies a timer's expiration time (an alternative to deleting a timer and starting a new one). + * + * @param tid The timer ID. + * @param tick New expiration time. + * @return The new tick value. + * @retval -1 in case of failure. + */ +int64 timer_settick(int tid, int64 tick) +{ + int i; // search timer position ARR_FIND(0, BHEAP_LENGTH(timer_heap), i, BHEAP_DATA(timer_heap)[i] == tid); - if( i == BHEAP_LENGTH(timer_heap) ) { + if (i == BHEAP_LENGTH(timer_heap)) { ShowError("timer_settick: no such timer %d (%p(%s))\n", tid, timer_data[tid].func, search_timer_func_list(timer_data[tid].func)); return -1; } @@ -373,13 +384,18 @@ int64 timer_settick(int tid, int64 tick) { return tick; } -/// Executes all expired timers. -/// Returns the value of the smallest non-expired timer (or 1 second if there aren't any). -int do_timer(int64 tick) { +/** + * Executes all expired timers. + * + * @param tick The current tick. + * @return The value of the smallest non-expired timer (or 1 second if there aren't any). + */ +int do_timer(int64 tick) +{ int64 diff = TIMER_MAX_INTERVAL; // return value // process all timers one by one - while( BHEAP_LENGTH(timer_heap) ) { + while (BHEAP_LENGTH(timer_heap) > 0) { int tid = BHEAP_PEEK(timer_heap);// top element in heap (smallest tick) diff = DIFF_TICK(timer_data[tid].tick, tick); |