diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-07-12 10:56:36 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-07-12 10:56:36 -0700 |
commit | 99bc91a3c939e07f2d754a67dce60a55d509b3c1 (patch) | |
tree | 68b8457a3906e4a1e28b325746799afbca9619f7 /src/rmd_get_frame.c | |
parent | 95e8bdaa25c9bf840c41995aac3fb141468a72b3 (diff) |
get_frame: insert brief sleep when paused
rmdGetFrame() can't just block on pause_cond because it services the
event loop, which may be the very thing responsible for unpausing
when not triggered by an external signal.
The existing code handles this correctly but it spins on polling
the paused flag and running the event loop when paused.
This commit just adds a short delay to that cycle so the rmdGetFrame
thread doesn't pointlessly burn CPU while paused.
Diffstat (limited to 'src/rmd_get_frame.c')
-rw-r--r-- | src/rmd_get_frame.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/rmd_get_frame.c b/src/rmd_get_frame.c index 8d8b8d8..3f5c084 100644 --- a/src/rmd_get_frame.c +++ b/src/rmd_get_frame.c @@ -45,6 +45,7 @@ #include <sys/shm.h> #include <errno.h> #include <stdlib.h> +#include <time.h> /* clip_event_area dejavu */ @@ -345,8 +346,16 @@ void *rmdGetFrame(ProgData *pdata) { //events (if not full_shots) rmdEventLoop(pdata); - if (pdata->paused) + if (pdata->paused) { + /* This is a bit janky, but there's need to service the event loop + * when paused, so instead of blocking on pause_cond, a short sleep + * is performed. + * Since the timer keeps running currently when paused, the above + * cond_wait() will never prevent us from reaching here. + */ + nanosleep(&(struct timespec){ .tv_nsec = 50000000 }, NULL); continue; + } //switch back and front buffers (full_shots only) if (d_buff) |