summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2024-10-06 23:28:31 -0700
committerVito Caputo <vcaputo@pengaru.com>2024-10-08 01:31:31 -0700
commit862c618c45d75d6f736f6b129943a5063e60c9eb (patch)
treea49bc561645948545da3f03270e8339b462567ef
parent644f0d1e8ee044f05ea530b58479820152f4e545 (diff)
vcr: switch to ppoll() and return microseconds delay
This is mostly preparotory for having more precision in a computed delay, but is also arguably just finishing what was started when adding the _us suffixes throughout. A future commit should also rework signal stuff to only unblock signals in ppoll().
-rw-r--r--src/charts.c2
-rw-r--r--src/vcr.c18
2 files changed, 14 insertions, 6 deletions
diff --git a/src/charts.c b/src/charts.c
index 24ffe7d..fd66932 100644
--- a/src/charts.c
+++ b/src/charts.c
@@ -1362,7 +1362,7 @@ int vwm_charts_update(vwm_charts_t *charts, int *desired_delay_us)
}
/* TODO: make some effort to compute how long to sleep, but this is perfectly fine for now. */
- *desired_delay_us = charts->sampling_interval_secs == INFINITY ? -1 : charts->sampling_interval_secs * 300.0;
+ *desired_delay_us = charts->sampling_interval_secs == INFINITY ? -1 : charts->sampling_interval_secs * 300000.0;
return ret;
}
diff --git a/src/vcr.c b/src/vcr.c
index f97b576..10d2caf 100644
--- a/src/vcr.c
+++ b/src/vcr.c
@@ -51,6 +51,7 @@
* positions.
*/
+#define _GNU_SOURCE /* for ppoll() */
#include <assert.h>
#include <math.h>
#include <poll.h>
@@ -412,9 +413,16 @@ int vcr_backend_get_dimensions(vcr_backend_t *vbe, int *res_width, int *res_heig
/* returns 1 if the backend has events to process, 0 on timeout/error. */
int vcr_backend_poll(vcr_backend_t *vbe, int timeout_us)
{
- /* FIXME TODO: should probably switch to ppoll() and keep signals blocked outside of
- * while blocked in ppoll(). Then ppoll() becomes our signal delivery/handling point...
- */
+ struct timespec ts, *pto = NULL;
+
+ /* TODO: keep signals blocked outside of ppoll() */
+
+ if (timeout_us >= 0) {
+ ts.tv_sec = timeout_us / 10000000;
+ ts.tv_nsec = (timeout_us - (ts.tv_sec * 10000000)) * 1000;
+ pto = &ts;
+ }
+
switch (vbe->type) {
#ifdef USE_XLIB
case VCR_BACKEND_TYPE_XLIB: {
@@ -426,11 +434,11 @@ int vcr_backend_poll(vcr_backend_t *vbe, int timeout_us)
if (XPending(vbe->xlib.xserver->display))
return 1;
- return poll(&pfd, 1, timeout_us);
+ return ppoll(&pfd, 1, pto, NULL);
}
#endif
case VCR_BACKEND_TYPE_MEM:
- return poll(NULL, 0, timeout_us);
+ return ppoll(NULL, 0, pto, NULL);
default:
assert(0);
© All Rights Reserved