rate_ctr: Make it safe to call rate_ctr_init() several times

There might be library code that has rate counters, and if the main
program calls rate_ctr_init() a second time, we can skip the second
initialization.

Change-Id: I6f5342a77518599eb5ac9a0f0605917a78fcc387
This commit is contained in:
Harald Welte 2021-11-14 20:45:07 +01:00
parent 1f666e875d
commit 5eb67c2d66
1 changed files with 4 additions and 0 deletions

View File

@ -354,6 +354,10 @@ static void rate_ctr_timer_cb(void *data)
* \returns 0 on success; negative on error */
int rate_ctr_init(void *tall_ctx)
{
/* ignore repeated initialization */
if (osmo_timer_pending(&rate_ctr_timer))
return 0;
tall_rate_ctr_ctx = tall_ctx;
osmo_timer_setup(&rate_ctr_timer, rate_ctr_timer_cb, NULL);
osmo_timer_schedule(&rate_ctr_timer, 1, 0);