diff options
author | Mauro Sardara <msardara@cisco.com> | 2020-07-29 09:05:08 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2020-09-09 11:08:44 +0200 |
commit | aba0a8ce4aeae0392b71658e9afaedc0d857a1a7 (patch) | |
tree | 739c9b88fd6696a992893c4f4d1c2af7c100032d /hicn-light/src/hicn/core/prefix_stats.c | |
parent | d5071d0c80e1da5e28c2430ba4b579b886373cd2 (diff) |
[HICN-555] Reworked loop
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Change-Id: Ia837da43b797a3f4d30d832e7ad2b0ec8cc3fefe
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/core/prefix_stats.c')
-rw-r--r-- | hicn-light/src/hicn/core/prefix_stats.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/hicn-light/src/hicn/core/prefix_stats.c b/hicn-light/src/hicn/core/prefix_stats.c index c32665950..b52964e03 100644 --- a/hicn-light/src/hicn/core/prefix_stats.c +++ b/hicn-light/src/hicn/core/prefix_stats.c @@ -5,6 +5,7 @@ #include <hicn/core/connection_table.h> #include <hicn/base/loop.h> +#include <hicn/util/log.h> #include <hicn/core/ticks.h> #include <hicn/policy.h> #include <hicn/core/fib.h> @@ -15,10 +16,10 @@ #define STATS_INTERVAL 1000 /* ms */ static -void -prefix_stats_mgr_tick(prefix_stats_mgr_t * mgr, int fd, void * data) +int +prefix_stats_mgr_tick(void * mgr_arg, int fd, void * data) { - + prefix_stats_mgr_t * mgr = mgr_arg; assert(mgr); assert(!data); @@ -31,15 +32,25 @@ prefix_stats_mgr_tick(prefix_stats_mgr_t * mgr, int fd, void * data) fib_foreach_entry(fib, entry, { prefix_stats_update(&entry->prefix_stats, &entry->prefix_counters, now); }); + + return 0; } int prefix_stats_mgr_initialize(prefix_stats_mgr_t * mgr, void * forwarder) { mgr->forwarder = forwarder; - mgr->timer_fd = loop_register_timer(MAIN_LOOP, STATS_INTERVAL, mgr, prefix_stats_mgr_tick, NULL); - if (mgr->timer_fd < 0) + + loop_timer_create(&mgr->timer, MAIN_LOOP, mgr, prefix_stats_mgr_tick, NULL); + if (!mgr->timer) { + ERROR("Error allocating prefix stats mgr timer."); + return -1; + } + + if (loop_timer_register(mgr->timer, STATS_INTERVAL) < 0) { + ERROR("Error registering prefix stats mgr timer."); return -1; + } return 0; } @@ -47,10 +58,10 @@ prefix_stats_mgr_initialize(prefix_stats_mgr_t * mgr, void * forwarder) void prefix_stats_mgr_finalize(prefix_stats_mgr_t * mgr) { - loop_unregister_timer(MAIN_LOOP, mgr->timer_fd); + loop_event_unregister(mgr->timer); + loop_event_free(mgr->timer); } - void prefix_stats_on_retransmission(const prefix_stats_mgr_t * mgr, prefix_counters_t * counters, const nexthops_t * nexthops) |