2010-02-20 19:34:29 +00:00
|
|
|
/*
|
|
|
|
* (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-08-17 10:46:48 +00:00
|
|
|
/*! \defgroup timer Osmocom timers
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \file timer.h
|
|
|
|
* \brief Osmocom timer handling routines
|
|
|
|
*/
|
|
|
|
|
2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2010-02-20 19:34:29 +00:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
2016-09-22 01:58:13 +00:00
|
|
|
#include <stdbool.h>
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-03-22 15:36:13 +00:00
|
|
|
#include <osmocom/core/linuxlist.h>
|
2011-09-26 09:45:03 +00:00
|
|
|
#include <osmocom/core/linuxrbtree.h>
|
2010-02-20 19:34:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer management:
|
2011-05-07 10:42:28 +00:00
|
|
|
* - Create a struct osmo_timer_list
|
2010-02-20 19:34:29 +00:00
|
|
|
* - Fill out timeout and use add_timer or
|
2015-11-02 19:18:11 +00:00
|
|
|
* use osmo_timer_schedule to schedule a timer in
|
2010-02-20 19:34:29 +00:00
|
|
|
* x seconds and microseconds from now...
|
2015-11-02 19:18:11 +00:00
|
|
|
* - Use osmo_timer_del to remove the timer
|
2010-02-20 19:34:29 +00:00
|
|
|
*
|
|
|
|
* Internally:
|
|
|
|
* - We hook into select.c to give a timeval of the
|
|
|
|
* nearest timer. On already passed timers we give
|
|
|
|
* it a 0 to immediately fire after the select
|
2015-11-02 19:18:11 +00:00
|
|
|
* - osmo_timers_update will call the callbacks and
|
|
|
|
* remove the timers.
|
2010-02-20 19:34:29 +00:00
|
|
|
*
|
|
|
|
*/
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief A structure representing a single instance of a timer */
|
2011-05-07 10:42:28 +00:00
|
|
|
struct osmo_timer_list {
|
2011-09-26 09:45:03 +00:00
|
|
|
struct rb_node node; /*!< \brief rb-tree node header */
|
|
|
|
struct llist_head list; /*!< \brief internal list header */
|
2011-08-16 21:26:52 +00:00
|
|
|
struct timeval timeout; /*!< \brief expiration time */
|
|
|
|
unsigned int active : 1; /*!< \brief is it active? */
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
void (*cb)(void*); /*!< \brief call-back called at timeout */
|
|
|
|
void *data; /*!< \brief user data for callback */
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timer management
|
|
|
|
*/
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2011-05-07 10:42:28 +00:00
|
|
|
void osmo_timer_add(struct osmo_timer_list *timer);
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2011-05-07 10:42:28 +00:00
|
|
|
void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds);
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2011-05-07 10:42:28 +00:00
|
|
|
void osmo_timer_del(struct osmo_timer_list *timer);
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2011-05-07 10:42:28 +00:00
|
|
|
int osmo_timer_pending(struct osmo_timer_list *timer);
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2012-07-13 10:21:04 +00:00
|
|
|
int osmo_timer_remaining(const struct osmo_timer_list *timer,
|
|
|
|
const struct timeval *now,
|
|
|
|
struct timeval *remaining);
|
2011-08-16 21:26:52 +00:00
|
|
|
/*
|
2010-02-20 19:34:29 +00:00
|
|
|
* internal timer list management
|
|
|
|
*/
|
2011-07-16 08:15:16 +00:00
|
|
|
struct timeval *osmo_timers_nearest(void);
|
|
|
|
void osmo_timers_prepare(void);
|
|
|
|
int osmo_timers_update(void);
|
2011-05-07 10:42:28 +00:00
|
|
|
int osmo_timers_check(void);
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2016-09-22 01:58:13 +00:00
|
|
|
int osmo_gettimeofday(struct timeval *tv, struct timezone *tz);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timer override
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern bool osmo_gettimeofday_override;
|
|
|
|
extern struct timeval osmo_gettimeofday_override_time;
|
|
|
|
void osmo_gettimeofday_override_add(time_t secs, suseconds_t usecs);
|
|
|
|
|
2012-04-18 19:53:23 +00:00
|
|
|
/*! @} */
|