Commit Graph

29 Commits

Author SHA1 Message Date
Eric Wild 06747d5720 timer.c: make timers thread safe
This is implicitly used by the libosmocore select abstraction, which
might be used in multiple threads at the same time.

Change-Id: I5a3802c94af6ff0315f1553f20870342d51ce726
2020-04-19 02:21:05 +02:00
Vadim Yanitskiy bc29b2660f Doxygen: fix documentation of osmo_timer_setup()
This change fixes the following Doxygen warnings:

  timer.c:69: warning: argument 'callback' of command @param is not
              found in the argument list of
              osmo_timer_setup(struct osmo_timer_list *timer,
                               void(*cb)(void *data), void *data)
  timer.c:69: warning: argument 'pointer' of command @param is not
              found in the argument list of
              osmo_timer_setup(struct osmo_timer_list *timer,
                               void(*cb)(void *data), void *data)
  core/timer.h:70: warning: The following parameters of
                   osmo_timer_setup(struct osmo_timer_list *timer,
                   void(*cb)(void *data), void *data)
                   are not documented:
                     parameter 'cb'
                     parameter 'data'

Change-Id: If5668f40a7bfde2f4f22329a071c8c6eff23b99e
2019-03-27 08:56:21 +01:00
Harald Welte aafc27ce37 timer: fixup whitespace issues
Change-Id: Ic0c8fc407a45ff4b0d3da1d3e4fdf8885b5bca9b
2017-12-22 16:48:14 +01:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Harald Welte 0047602435 timer: use timerclear() rather than explicit tv_set = tv_usec = 0
Change-Id: I2735fc8d19fd68ef2c14a31e83cb396dc2e05587
2017-05-15 19:00:43 +02:00
Pablo Neira Ayuso 44f423f117 timer: add osmo_timer_setup()
Add a new function timer function to set up the timer, similar to what
we have in the Linux kernel. This patch also converts existing opencoded
timer setup in the libosmocore tree as initial client of this new
function.

This patch implicitly removes function callback passed by reference that
defeat compile time type validation.

Compile-tested only, but I ran make check that reports success when
testing timer infrastructure.

Change-Id: I2fa49972ecaab3748b25168b26d92034e9145666
2017-05-09 12:10:51 +02:00
Alexander Couzens ec9bd52628 timer: only call the callback if not NULL
Fix a crash in osmo-sgsn.

Change-Id: I04d58d9580708cc0f6d0f4aa17d3e9f2c6235c8e
2016-11-28 23:23:09 +01:00
Neels Hofmeyr 8e2f7e87f4 add osmo_gettimeofday as a shim around gettimeofday
This allows feeding a custom time for unit tests by overriding
osmo_gettimeofday.

Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
2016-09-22 07:18:39 +02:00
Harald Welte 2d2e2cca0d Update doxygen annotations in libosmocore
This adds and improves doxygen API descriptions all over libosmocore,
reducing the 'white spots' that don't have any documentation.
2016-05-05 18:49:27 +02:00
Holger Hans Peter Freyther 3f838b717e timer: Fix compiler warning about timeval
timer.c:27:23: warning: tentative definition of variable with internal linkage has incomplete
      non-array type 'struct timeval' [-Wtentative-definition-incomplete-type]
static struct timeval nearest;
                      ^
timer.c:27:15: note: forward declaration of 'struct timeval'
static struct timeval nearest;
2015-08-21 19:45:08 +00:00
Holger Hans Peter Freyther 8e5435a864 timer: Use the now parameter when it is not NULL
The code would have used an uninitialized current_time in case
"now" was not NULL. As now is const and timersub expects a non
const parameter I decided to copy now into current_time.

Fixes: CID #1040661
2014-05-23 08:37:02 +02:00
Katerina Barone-Adesi c28c6a02d2 misc: Doxygen tweaks: fixed some typos and minor errors
Doxygen generates quite a lot of warnings on libosmocore. Some of them
are obvious typos - this patch aims to fix such low-hanging fruit.
2013-02-15 13:27:59 +01:00
Harald Welte de6e4983e7 add some missing doxygen annotation for libosmocore functions 2013-01-11 09:43:32 +01:00
Harald Welte e30b6ac5d1 timer: Add function osmo_timer_remaining() to determine remainign time 2012-07-13 12:22:20 +02:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00
Pablo Neira Ayuso a71b8eaca7 timer: Better fix to the timer re-scheduling situation
As it turns out, the previous fix didn't cover the case of a
timer X being re-scheduled inside a timer call back expiring at
the same time as the previous X instance.

Written-by: Pablo Neira Ayuso <pablo@gnumonks.org>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-11-13 10:11:31 +01:00
Sylvain Munaut aeeb7070f8 core/timer: Allow an already scheduled timer to be re-scheduled at a new time
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-11-12 23:23:35 +01:00
Sylvain Munaut 07f1103782 timer: Add compatibility header with timer helpers
Some of these are not always present, especially when cross compiling

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-10-21 21:55:29 +02:00
Sylvain Munaut 0061dedaae timer: Simplify osmo_timers_nearest even more
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-10-18 20:11:03 +02:00
Sylvain Munaut 955fdb039e timer: Fix implementation of osmo_timers_nearest causing high CPU load
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-10-17 23:03:57 +02:00
Pablo Neira Ayuso 066c912fd3 timer: add scalable RB-tree based timer infrastructure
This patch adds RB-tree based timers which scales better than the
previous list-based implementation.

It does not require any API changes. It breaks ABI because the
osmo_timer_list structure has changed though (to avoid this in
the future, we can put internal data in some private structure).

The following table summarizes the worst-case computational complexity
of this new implementation versus the previous one:

                                rb-tree         list-based
                                -------         ----------
calculate next timer to expire  O(1)            O(n)
insertion of new timer          O(log n)        O(n)
deletion of timer               O(log n)        O(1)
timer-fired scheduler           O(log n)        O(3n)

The most repeated cases are:

* the calculation of the next timer to expire, that happens in every
  loop of our select function.

* the timer-fired scheduler execution.

This new implementation only loses in the deletion of timer scenario,
this happens because we may need to rebalance the tree after the
removal.

So I think there is some real gain if we have some situation in which
we have to handle lots of timers.
2011-10-17 13:25:29 +02:00
Harald Welte ba6988bd89 some more doxygen work (include the notion of modules) 2011-08-17 17:14:11 +02:00
Harald Welte 7e82020259 timer: use (void) for functions that take no arguments
This has been detected by http://smatch.sourceforge.net/
2011-07-16 12:03:46 +02:00
Pablo Neira Ayuso 0b21c1c885 timer: use namespace prefix osmo_timer*
Summary of changes:

s/struct timer_list/struct osmo_timer_list/g
s/bsc_add_timer/osmo_timer_add/g
s/bsc_schedule_timer/osmo_timer_schedule/g
s/bsc_del_timer/osmo_timer_del/g
s/bsc_timer_pending/osmo_timer_pending/g
s/bsc_nearest_timer/osmo_timers_nearest/g
s/bsc_prepare_timers/osmo_timers_prepare/g
s/bsc_update_timers/osmo_timers_update/g
s/bsc_timer_check/osmo_timers_check/g
2011-05-07 13:00:51 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00
Harald Welte ec8b4501c7 intial checkin of the libosmocore project 2010-02-20 20:34:29 +01:00