Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2008,2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 3 | * (C) 2011 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 6 | * Authors: Holger Hans Peter Freyther <zecke@selfish.org> |
| 7 | * Harald Welte <laforge@gnumonks.org> |
| 8 | * Pablo Neira Ayuso <pablo@gnumonks.org> |
| 9 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | * |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | * |
| 26 | */ |
| 27 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 28 | |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 29 | /*! \addtogroup timer |
| 30 | * @{ |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 31 | * Osmocom timer abstraction; modelled after linux kernel timers |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 32 | * |
| 33 | * \file timer.c */ |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 34 | |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 35 | #include <assert.h> |
| 36 | #include <string.h> |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 37 | #include <limits.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 38 | #include <osmocom/core/timer.h> |
Sylvain Munaut | 07f1103 | 2011-10-21 21:55:29 +0200 | [diff] [blame] | 39 | #include <osmocom/core/timer_compat.h> |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 40 | #include <osmocom/core/linuxlist.h> |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 41 | |
Holger Hans Peter Freyther | 3f838b7 | 2015-08-20 18:17:15 +0000 | [diff] [blame] | 42 | /* These store the amount of time that we wait until next timer expires. */ |
Eric | 06747d5 | 2020-04-19 02:09:28 +0200 | [diff] [blame] | 43 | static __thread struct timeval nearest; |
| 44 | static __thread struct timeval *nearest_p; |
Holger Hans Peter Freyther | 3f838b7 | 2015-08-20 18:17:15 +0000 | [diff] [blame] | 45 | |
Eric | 06747d5 | 2020-04-19 02:09:28 +0200 | [diff] [blame] | 46 | static __thread struct rb_root timer_root = RB_ROOT; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 47 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 48 | static void __add_timer(struct osmo_timer_list *timer) |
| 49 | { |
| 50 | struct rb_node **new = &(timer_root.rb_node); |
| 51 | struct rb_node *parent = NULL; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 52 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 53 | while (*new) { |
| 54 | struct osmo_timer_list *this; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 55 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 56 | this = container_of(*new, struct osmo_timer_list, node); |
| 57 | |
| 58 | parent = *new; |
| 59 | if (timercmp(&timer->timeout, &this->timeout, <)) |
| 60 | new = &((*new)->rb_left); |
| 61 | else |
| 62 | new = &((*new)->rb_right); |
Harald Welte | aafc27c | 2017-11-20 20:22:22 +0100 | [diff] [blame] | 63 | } |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 64 | |
Harald Welte | aafc27c | 2017-11-20 20:22:22 +0100 | [diff] [blame] | 65 | rb_link_node(&timer->node, parent, new); |
| 66 | rb_insert_color(&timer->node, &timer_root); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 67 | } |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 68 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 69 | /*! set up timer callback and data |
Pablo Neira Ayuso | 44f423f | 2017-05-08 18:00:28 +0200 | [diff] [blame] | 70 | * \param[in] timer the timer that should be added |
Vadim Yanitskiy | bc29b26 | 2019-03-26 01:12:43 +0700 | [diff] [blame] | 71 | * \param[in] cb function to be called when timer expires |
| 72 | * \param[in] data pointer to data that passed to the callback function |
Pablo Neira Ayuso | 44f423f | 2017-05-08 18:00:28 +0200 | [diff] [blame] | 73 | */ |
| 74 | void osmo_timer_setup(struct osmo_timer_list *timer, void (*cb)(void *data), |
| 75 | void *data) |
| 76 | { |
| 77 | timer->cb = cb; |
| 78 | timer->data = data; |
| 79 | } |
| 80 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 81 | /*! add a new timer to the timer management |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 82 | * \param[in] timer the timer that should be added |
| 83 | */ |
Pablo Neira Ayuso | 0b21c1c | 2011-05-07 12:42:28 +0200 | [diff] [blame] | 84 | void osmo_timer_add(struct osmo_timer_list *timer) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 85 | { |
Pablo Neira Ayuso | a71b8ea | 2011-11-13 10:11:31 +0100 | [diff] [blame] | 86 | osmo_timer_del(timer); |
| 87 | timer->active = 1; |
| 88 | INIT_LLIST_HEAD(&timer->list); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 89 | __add_timer(timer); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 92 | /*! schedule a timer at a given future relative time |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 93 | * \param[in] timer the to-be-added timer |
| 94 | * \param[in] seconds number of seconds from now |
| 95 | * \param[in] microseconds number of microseconds from now |
| 96 | * |
| 97 | * This function can be used to (re-)schedule a given timer at a |
| 98 | * specified number of seconds+microseconds in the future. It will |
| 99 | * internally add it to the timer management data structures, thus |
| 100 | * osmo_timer_add() is automatically called. |
| 101 | */ |
Pablo Neira Ayuso | 0b21c1c | 2011-05-07 12:42:28 +0200 | [diff] [blame] | 102 | void |
| 103 | osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 104 | { |
| 105 | struct timeval current_time; |
| 106 | |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 107 | osmo_gettimeofday(¤t_time, NULL); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 108 | timer->timeout.tv_sec = seconds; |
| 109 | timer->timeout.tv_usec = microseconds; |
| 110 | timeradd(&timer->timeout, ¤t_time, &timer->timeout); |
Pablo Neira Ayuso | 0b21c1c | 2011-05-07 12:42:28 +0200 | [diff] [blame] | 111 | osmo_timer_add(timer); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 114 | /*! delete a timer from timer management |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 115 | * \param[in] timer the to-be-deleted timer |
| 116 | * |
| 117 | * This function can be used to delete a previously added/scheduled |
| 118 | * timer from the timer management code. |
| 119 | */ |
Pablo Neira Ayuso | 0b21c1c | 2011-05-07 12:42:28 +0200 | [diff] [blame] | 120 | void osmo_timer_del(struct osmo_timer_list *timer) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 121 | { |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 122 | if (timer->active) { |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 123 | timer->active = 0; |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 124 | rb_erase(&timer->node, &timer_root); |
| 125 | /* make sure this is not already scheduled for removal. */ |
| 126 | if (!llist_empty(&timer->list)) |
| 127 | llist_del_init(&timer->list); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 131 | /*! check if given timer is still pending |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 132 | * \param[in] timer the to-be-checked timer |
| 133 | * \return 1 if pending, 0 otherwise |
| 134 | * |
| 135 | * This function can be used to determine whether a given timer |
| 136 | * has alredy expired (returns 0) or is still pending (returns 1) |
| 137 | */ |
Pau Espin Pedrol | a488639 | 2021-04-29 16:36:53 +0200 | [diff] [blame] | 138 | int osmo_timer_pending(const struct osmo_timer_list *timer) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 139 | { |
| 140 | return timer->active; |
| 141 | } |
| 142 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 143 | /*! compute the remaining time of a timer |
Harald Welte | e30b6ac | 2012-07-13 12:21:04 +0200 | [diff] [blame] | 144 | * \param[in] timer the to-be-checked timer |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 145 | * \param[in] now the current time (NULL if not known) |
Harald Welte | e30b6ac | 2012-07-13 12:21:04 +0200 | [diff] [blame] | 146 | * \param[out] remaining remaining time until timer fires |
| 147 | * \return 0 if timer has not expired yet, -1 if it has |
| 148 | * |
| 149 | * This function can be used to determine the amount of time |
| 150 | * remaining until the expiration of the timer. |
| 151 | */ |
| 152 | int osmo_timer_remaining(const struct osmo_timer_list *timer, |
| 153 | const struct timeval *now, |
| 154 | struct timeval *remaining) |
| 155 | { |
| 156 | struct timeval current_time; |
| 157 | |
Holger Hans Peter Freyther | 8e5435a | 2014-05-23 08:37:02 +0200 | [diff] [blame] | 158 | if (!now) |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 159 | osmo_gettimeofday(¤t_time, NULL); |
Holger Hans Peter Freyther | 8e5435a | 2014-05-23 08:37:02 +0200 | [diff] [blame] | 160 | else |
| 161 | current_time = *now; |
Harald Welte | e30b6ac | 2012-07-13 12:21:04 +0200 | [diff] [blame] | 162 | |
| 163 | timersub(&timer->timeout, ¤t_time, remaining); |
| 164 | |
| 165 | if (remaining->tv_sec < 0) |
| 166 | return -1; |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 171 | /*! Determine time between now and the nearest timer |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 172 | * \returns pointer to timeval of nearest timer, NULL if there is none |
| 173 | * |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 174 | * if we have a nearest time return the delta between the current |
| 175 | * time and the time of the nearest timer. |
| 176 | * If the nearest timer timed out return NULL and then we will |
| 177 | * dispatch everything after the select |
| 178 | */ |
Harald Welte | 7e82020 | 2011-07-16 10:15:16 +0200 | [diff] [blame] | 179 | struct timeval *osmo_timers_nearest(void) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 180 | { |
Sylvain Munaut | 0061ded | 2011-10-18 20:11:03 +0200 | [diff] [blame] | 181 | /* nearest_p is exactly what we need already: NULL if nothing is |
| 182 | * waiting, {0,0} if we must dispatch immediately, and the correct |
| 183 | * delay if we need to wait */ |
| 184 | return nearest_p; |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 185 | } |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 186 | |
Harald Welte | b904e42 | 2020-10-18 21:24:13 +0200 | [diff] [blame] | 187 | /*! Determine time between now and the nearest timer in milliseconds |
| 188 | * \returns number of milliseconds until nearest timer expires; -1 if no timers pending |
| 189 | */ |
| 190 | int osmo_timers_nearest_ms(void) |
| 191 | { |
| 192 | int nearest_ms; |
| 193 | |
| 194 | if (!nearest_p) |
| 195 | return -1; |
| 196 | |
| 197 | nearest_ms = nearest_p->tv_sec * 1000; |
| 198 | nearest_ms += nearest_p->tv_usec / 1000; |
| 199 | |
| 200 | return nearest_ms; |
| 201 | } |
| 202 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 203 | static void update_nearest(struct timeval *cand, struct timeval *current) |
| 204 | { |
| 205 | if (cand->tv_sec != LONG_MAX) { |
| 206 | if (timercmp(cand, current, >)) |
| 207 | timersub(cand, current, &nearest); |
| 208 | else { |
| 209 | /* loop again inmediately */ |
Harald Welte | 0047602 | 2017-05-15 14:29:13 +0200 | [diff] [blame] | 210 | timerclear(&nearest); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 211 | } |
| 212 | nearest_p = &nearest; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 213 | } else { |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 214 | nearest_p = NULL; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 215 | } |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 218 | /*! Find the nearest time and update nearest_p */ |
Harald Welte | 7e82020 | 2011-07-16 10:15:16 +0200 | [diff] [blame] | 219 | void osmo_timers_prepare(void) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 220 | { |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 221 | struct rb_node *node; |
| 222 | struct timeval current; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 223 | |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 224 | osmo_gettimeofday(¤t, NULL); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 225 | |
| 226 | node = rb_first(&timer_root); |
| 227 | if (node) { |
| 228 | struct osmo_timer_list *this; |
| 229 | this = container_of(node, struct osmo_timer_list, node); |
| 230 | update_nearest(&this->timeout, ¤t); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 231 | } else { |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 232 | nearest_p = NULL; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 236 | /*! fire all timers... and remove them */ |
Harald Welte | 7e82020 | 2011-07-16 10:15:16 +0200 | [diff] [blame] | 237 | int osmo_timers_update(void) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 238 | { |
| 239 | struct timeval current_time; |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 240 | struct rb_node *node; |
| 241 | struct llist_head timer_eviction_list; |
| 242 | struct osmo_timer_list *this; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 243 | int work = 0; |
| 244 | |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 245 | osmo_gettimeofday(¤t_time, NULL); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 246 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 247 | INIT_LLIST_HEAD(&timer_eviction_list); |
| 248 | for (node = rb_first(&timer_root); node; node = rb_next(node)) { |
| 249 | this = container_of(node, struct osmo_timer_list, node); |
| 250 | |
| 251 | if (timercmp(&this->timeout, ¤t_time, >)) |
| 252 | break; |
| 253 | |
| 254 | llist_add(&this->list, &timer_eviction_list); |
| 255 | } |
| 256 | |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 257 | /* |
| 258 | * The callbacks might mess with our list and in this case |
| 259 | * even llist_for_each_entry_safe is not safe to use. To allow |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 260 | * osmo_timer_del to be called from within the callback we need |
| 261 | * to restart the iteration for each element scheduled for removal. |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 262 | * |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 263 | * The problematic scenario is the following: Given two timers A |
| 264 | * and B that have expired at the same time. Thus, they are both |
| 265 | * in the eviction list in this order: A, then B. If we remove |
| 266 | * timer B from the A's callback, we continue with B in the next |
| 267 | * iteration step, leading to an access-after-release. |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 268 | */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 269 | restart: |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 270 | llist_for_each_entry(this, &timer_eviction_list, list) { |
| 271 | osmo_timer_del(this); |
Alexander Couzens | ec9bd52 | 2016-11-28 23:22:14 +0100 | [diff] [blame] | 272 | if (this->cb) |
| 273 | this->cb(this->data); |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 274 | work = 1; |
| 275 | goto restart; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | return work; |
| 279 | } |
| 280 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 281 | /*! Check how many timers we have in the system |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 282 | * \returns number of \ref osmo_timer_list registered */ |
Pablo Neira Ayuso | 0b21c1c | 2011-05-07 12:42:28 +0200 | [diff] [blame] | 283 | int osmo_timers_check(void) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 284 | { |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 285 | struct rb_node *node; |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 286 | int i = 0; |
| 287 | |
Pablo Neira Ayuso | 066c912 | 2011-09-26 11:45:03 +0200 | [diff] [blame] | 288 | for (node = rb_first(&timer_root); node; node = rb_next(node)) { |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 289 | i++; |
| 290 | } |
| 291 | return i; |
| 292 | } |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 293 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 294 | /*! @} */ |