summaryrefslogtreecommitdiff
path: root/src/common/timer.c
diff options
context:
space:
mode:
authorPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-22 22:50:45 +0200
committerPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-22 22:50:45 +0200
commitc0c254f14d0d65a8b7ec50720ed8d98b5a04919a (patch)
tree0fc26c057880491c12358a6cc9d0f37d15155dc3 /src/common/timer.c
parent0b63deefd251a06b50a333facd6ad0e099e942b2 (diff)
downloadhercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.gz
hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.bz2
hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.xz
hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.zip
Binary heap fix & improvement.
Fixed a bug when removing last element of binary heap (its parent would be removed instead if it had the same value). Binary heap now allows custom swapper function/macro. Added `swap_ptr` macro to swap two pointers in place (`swap` is not suitable for pointers). This allows to store pointers in binary heap.
Diffstat (limited to 'src/common/timer.c')
-rw-r--r--src/common/timer.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/timer.c b/src/common/timer.c
index 955a971c8..f019c6927 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -195,7 +195,7 @@ unsigned int timer_gettick(void) {
/// Adds a timer to the timer_heap
static void push_timer_heap(int tid) {
BHEAP_ENSURE(timer_heap, 1, 256);
- BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP);
+ BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, swap);
}
/*==========================
@@ -322,9 +322,9 @@ int timer_settick(int tid, unsigned int tick) {
return (int)tick;// nothing to do, already in propper position
// pop and push adjusted timer
- BHEAP_POPINDEX(timer_heap, i, DIFFTICK_MINTOPCMP);
+ BHEAP_POPINDEX(timer_heap, i, DIFFTICK_MINTOPCMP, swap);
timer_data[tid].tick = tick;
- BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP);
+ BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, swap);
return (int)tick;
}
@@ -342,7 +342,7 @@ int do_timer(unsigned int tick) {
break; // no more expired timers to process
// remove timer
- BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP);
+ BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP, swap);
timer_data[tid].type |= TIMER_REMOVE_HEAP;
if( timer_data[tid].func ) {