More minor bugfixes

- make pollcat_loop() work as expected with no structs linked, by
  - calling usleep() instead of poll()
  - refactoring delay calculation and reset into pollcat_time_value()
- simplify pollcat_timer_dispatch() in case of slow callbacks
  - deprecate pollcat_timer_dispatch_thresh
- revise tests/timer.c to support two new options:
  - -s to monitor stdin with pollcat_fd_add()
  - -w to use pollcat_loop() instead of handling main-loop separately
- make pollcat_dump() always present in header, since it's always compiled in
- add Makefile rules for installing tests, for easier running on cross-compiled targets
This commit is contained in:
2025-09-18 13:28:27 -07:00
parent c7729ca9b6
commit d0dd5f7a4a
8 changed files with 143 additions and 90 deletions

View File

@@ -1,7 +1,7 @@
/** Wrapper structure for poll()
*
* This file is part of the Pollcat Library.
* Copyright (C) 2022 Expatria Technologies Inc.
* Copyright (C) 2022,2025 Expatria Technologies Inc.
* Contact: Morgan Hughes <morgan@expatria.ca>
*
* The Pollcat Library is free software: you can redistribute it and/or modify it under
@@ -284,6 +284,23 @@ void pollcat_time_reduce (int time)
pollcat_time_current = time;
}
/** Return the current timeout and reset the current timeout to the base value
*
* \return Timeout in milliseconds
*/
int pollcat_time_value (void)
{
/* latch current value, which may have been reduced by pollcat_time_reduce() */
int value = pollcat_time_current;
/* enforce minimum */
if ( value < pollcat_time_minimum )
value = pollcat_time_minimum;
/* reset to base before return, for next call */
pollcat_time_current = pollcat_time_base;
return value;
}
/** Wraps the system poll() command using the internal pollfd array and timeout
*
@@ -296,11 +313,7 @@ int pollcat_poll (void)
/* Auto init, no-return if failed */
pollcat_init();
if ( pollcat_time_current < pollcat_time_minimum )
pollcat_time_current = pollcat_time_minimum;
ret = poll(pollcat_list, pollcat_used, pollcat_time_current);
pollcat_time_current = pollcat_time_base;
ret = poll(pollcat_list, pollcat_used, pollcat_time_value());
return ret;
}