Commit Graph

19 Commits

Author SHA1 Message Date
Chrissie Caulfield
fde729e137
timer: Move state check to before time check (#479)
A timer in QB_POLL_ENTRY_JOBLIST doesn't necessarily
have a t->timerlist_handle so that deref can segv. Also
the comment assumes the timers are threaded - which as we have
decided is definitely not true. So it's safe to move the check
earlier.

In the tests, I've adjusted the timeouts so that they definitely
happen at different times. On some architectures they can fire
concurrently and in the wrong order.
2023-01-05 14:45:22 +00:00
Chrissie Caulfield
a60ca50b67
Fix pthread returns (#444)
pthread calls do not set errno, they return the error directly
2021-08-11 07:55:42 +01:00
Jan Friesse
48fff5eb58
Implement heap based timer list (#439)
* tlist: Add heap based implementation of timer list

Previous timer was sorted list implementation of priority queue
and very slow when number of timers increased. This is mostly
not a problem because usually only few timers are used.
But for application where bigger number of timers are needed
it may become problem.

Solution is to use binary heap based priority queue which is much
faster.

API is unchanged, just timerlist_destroy is added which should be called
to free heap array. This function also destroys mutex (omitted when
mutex was added).

* tests: Fix check loop mt test

test_th was accesed both by main thread and loop_timer thread resulting in
failure. Fix is to access test_tht in loop_timer thread.

Speed test is adding only 10000 items so it is reasonable
fast even with sorted linked list implementation.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
2021-03-18 07:27:25 +00:00
Chrissie Caulfield
d6e2bd1d6b
timers: Add some locking (#436)
Fix several locking issues reported by helgrind
2021-02-08 10:57:42 +00:00
Chris Murphy
08806c5301
master: Issue 390: Clarify documentation of qb_loop_timer_expire_time_get and provide new function to return previously documented behavior (#391)
Includes unit test addition by chrissie-c
2020-04-29 13:20:52 +01:00
Jan Pokorný
cfb15c7bcc
warnings cleanup: hdb+loop_timerlist: Wsign-compare: (canary?) variables
In case of hdb.c, the problem is that `check` public API (qb_hdb_handle
member struct) item (which should not be exposed publicly like this
in the first place!) is typed as `int32_t`, whereas it was to be
compared to `uint32_t` implementation-possessed local variables
(presumably derived from the same source), which made the compiler
upset (even though there was no real reason, integer promotion to
unsigned type would happily occur, which is furthermore expected to
be fully defined as these values come from `random` that shall
return non-negative integers below `INT32_MAX`).

Hence:
- type these local variables to `int32_t` just as well, which allows to
- simplify `random` return value handling, since they are expected to be
  zero-or-greater and the previously extra tested all-bits-on pattern
  makes undoubtfully for a negative numeric value in case of a signed
  integer with specified width (c.f. 7.18.1.1/C99), hence falling into
  complement of zero-or-greater; zero itself is also excluded for the
  reasons stated in the comment (which was pretty hazy and incorrect,
  so it gets overhaul as well)
- also superfluous typecasts are removed

Similar situation is with loop_timerlist.c, where we are actually fully
in charge of the struct member (private API), but there are good reasons
to stay consistent with the former file as the same applies to the
source of that value -- it comes from `random` (equivalent comment
is added here for greater symmetry).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-12-20 22:17:29 +01:00
Jan Pokorný
aed01bb452
maint: replace 0xffffffff constants with UNIT32_MAX
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-12-20 22:17:07 +01:00
Angus Salkeld
6d0d8bb670 TIMER: check for null timer handle
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-03-09 12:17:03 +11:00
Angus Salkeld
002f009941 Remove timerfd usage and go back to timelist.
timefd is using too much cpu and it is using up
file descriptors.

timelist is also more portable and now I have less
code to maintain.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-02-24 11:40:45 +11:00
Angus Salkeld
0d21be245b ARRAY: save memory (in the bins array) and allow holes in the array
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-02-22 17:30:19 +11:00
Angus Salkeld
1e4b33c9cf LOOP: make it possible to pass in NULL as the default loop instance
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-02-10 14:47:49 +11:00
Angus Salkeld
29d193112a LOOP: allow a timer to be created without returning the handle
This is if the user does not plan to delete the timer.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-01-23 16:04:49 +11:00
Angus Salkeld
98493d9ae8 Change Lindent options to break the procedure type.
so change:
int foo(void)

to

int
foo(void)

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-06-22 14:19:14 +10:00
Angus Salkeld
001b4a078c LOOP: make the return more consistent in qb_loop_timer_expire_time_get()
If there is any error return 0
 (meaning the timer is or has expired)

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-06-22 13:13:34 +10:00
Angus Salkeld
943b1c646b fix the FIXME's Jim pointed out
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-05-18 11:11:14 +10:00
Jim Meyering
9c467cb150 add FIXME comments for other NULL-deref-upon-OOM problems
* lib/ipc_us.c (handle_new_connection):
* lib/loop_job.c (qb_loop_jobs_create):
* lib/loop_poll.c (qb_loop_poll_create):
* lib/loop_timerlist.c (qb_loop_timer_create):
* lib/ringbuffer.c (qb_rb_open):
* lib/ipcc.c (qb_ipcc_connect): Likewise.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-05-17 21:32:29 +10:00
Angus Salkeld
8431910be0 LOOP: change timer handle from pointer to index + check.
This changes the timer hande from a live pointer to a handle
more like hdb handles (minus the ref counting).

What i like about this is it is not neccessary to clear
the applications handle using memset().

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-01-05 10:52:30 +11:00
Angus Salkeld
45ff679934 LOOP: change timers to be nano second based
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2010-12-13 12:23:45 +11:00
Angus Salkeld
dc08661297 LOOP: add support for timerfd
If available use timerfd_create() as it is
much more accurate than tlist.h

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2010-11-01 10:14:08 +11:00