summaryrefslogtreecommitdiff
path: root/src/common/timer.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-10-04 20:36:36 +0200
committerHaru <haru@dotalux.com>2015-10-11 00:23:36 +0200
commit5c22b636b315776ea3cd5d279344aac7f5a47548 (patch)
tree96070307820882d07df03597a94302dd6959cfdd /src/common/timer.c
parentda34200bfe78e6b8efcd08fc6511edcda900d483 (diff)
downloadhercules-5c22b636b315776ea3cd5d279344aac7f5a47548.tar.gz
hercules-5c22b636b315776ea3cd5d279344aac7f5a47548.tar.bz2
hercules-5c22b636b315776ea3cd5d279344aac7f5a47548.tar.xz
hercules-5c22b636b315776ea3cd5d279344aac7f5a47548.zip
Changed VECTOR/BHEAP/ARRAY macros to discourage usage of unsigned loop counters.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/timer.c')
-rw-r--r--src/common/timer.c34
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);