From 29b221671fd161546d82f66622740825ded406a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 26 Mar 2026 14:36:05 +0100 Subject: [PATCH] spa: remove `timerspec` members These are only used when the timer is set, so convert them to local variables. No functional changes intended. --- spa/plugins/audiotestsrc/audiotestsrc.c | 21 ++++++++------------- spa/plugins/support/node-driver.c | 14 ++++++-------- spa/plugins/support/null-audio-sink.c | 15 +++++++-------- spa/plugins/test/fakesink.c | 21 ++++++++------------- spa/plugins/test/fakesrc.c | 21 ++++++++------------- spa/plugins/videotestsrc/videotestsrc.c | 21 ++++++++------------- spa/plugins/vulkan/vulkan-compute-source.c | 21 ++++++++------------- 7 files changed, 53 insertions(+), 81 deletions(-) diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 5e7c521b8..e2f08ac26 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -120,7 +120,6 @@ struct impl { bool async; struct spa_source timer_source; - struct itimerspec timerspec; bool started; uint64_t start_time; @@ -317,21 +316,21 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) static void set_timer(struct impl *this, bool enabled) { if (this->async || this->props.live) { + struct itimerspec ts = {0}; + if (enabled) { if (this->props.live) { uint64_t next_time = this->start_time + this->elapsed_time; - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 1; + ts.it_value.tv_sec = 0; + ts.it_value.tv_nsec = 1; } - } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; } + spa_system_timerfd_settime(this->data_system, - this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL); + this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &ts, NULL); } } @@ -1105,10 +1104,6 @@ impl_init(const struct spa_handle_factory *factory, CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; if (this->data_loop) spa_loop_add_source(this->data_loop, &this->timer_source); diff --git a/spa/plugins/support/node-driver.c b/spa/plugins/support/node-driver.c index fa9cf3426..f0585a711 100644 --- a/spa/plugins/support/node-driver.c +++ b/spa/plugins/support/node-driver.c @@ -91,7 +91,6 @@ struct impl { struct spa_io_clock *clock; struct spa_source timer_source; - struct itimerspec timerspec; int clock_fd; bool started; @@ -182,13 +181,16 @@ static void set_timeout(struct impl *this, uint64_t next_time) * returning -ECANCELED.) * If timerfd is used with a non-realtime clock, the flag is ignored. * (Note that the flag only works in combination with SPA_FD_TIMER_ABSTIME.) */ + struct itimerspec ts; spa_log_trace(this->log, "set timeout %"PRIu64, next_time); - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_interval.tv_sec = 0; + ts.it_interval.tv_nsec = 0; spa_system_timerfd_settime(this->data_system, this->timer_source.fd, SPA_FD_TIMER_ABSTIME | - SPA_FD_TIMER_CANCEL_ON_SET, &this->timerspec, NULL); + SPA_FD_TIMER_CANCEL_ON_SET, &ts, NULL); } static inline uint64_t gettime_nsec(struct impl *this, clockid_t clock_id) @@ -1043,10 +1045,6 @@ impl_init(const struct spa_handle_factory *factory, this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; spa_loop_add_source(this->data_loop, &this->timer_source); diff --git a/spa/plugins/support/null-audio-sink.c b/spa/plugins/support/null-audio-sink.c index b804023b3..610adf9ce 100644 --- a/spa/plugins/support/null-audio-sink.c +++ b/spa/plugins/support/null-audio-sink.c @@ -114,7 +114,6 @@ struct impl { unsigned int started:1; unsigned int following:1; struct spa_source timer_source; - struct itimerspec timerspec; uint64_t next_time; }; @@ -179,11 +178,15 @@ static int impl_node_enum_params(void *object, int seq, static void set_timeout(struct impl *this, uint64_t next_time) { + struct itimerspec ts; + spa_log_trace(this->log, "set timeout %"PRIu64, next_time); - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_interval.tv_sec = 0; + ts.it_interval.tv_nsec = 0; spa_system_timerfd_settime(this->data_system, - this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL); + this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &ts, NULL); } static int set_timers(struct impl *this) @@ -929,10 +932,6 @@ impl_init(const struct spa_handle_factory *factory, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; spa_loop_add_source(this->data_loop, &this->timer_source); diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c index 71550300c..168de5473 100644 --- a/spa/plugins/test/fakesink.c +++ b/spa/plugins/test/fakesink.c @@ -74,7 +74,6 @@ struct impl { struct spa_callbacks callbacks; struct spa_source timer_source; - struct itimerspec timerspec; bool started; uint64_t start_time; @@ -180,21 +179,21 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, static void set_timer(struct impl *this, bool enabled) { if (this->callbacks.funcs || this->props.live) { + struct itimerspec ts = {0}; + if (enabled) { if (this->props.live) { uint64_t next_time = this->start_time + this->elapsed_time; - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 1; + ts.it_value.tv_sec = 0; + ts.it_value.tv_nsec = 1; } - } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; } + spa_system_timerfd_settime(this->data_system, - this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL); + this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &ts, NULL); } } @@ -767,10 +766,6 @@ impl_init(const struct spa_handle_factory *factory, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; if (this->data_loop) spa_loop_add_source(this->data_loop, &this->timer_source); diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index 28b37dab4..86dc44ac8 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -75,7 +75,6 @@ struct impl { struct spa_callbacks callbacks; struct spa_source timer_source; - struct itimerspec timerspec; bool started; uint64_t start_time; @@ -195,21 +194,21 @@ static int fill_buffer(struct impl *this, struct buffer *b) static void set_timer(struct impl *this, bool enabled) { if (this->callbacks.funcs || this->props.live) { + struct itimerspec ts = {0}; + if (enabled) { if (this->props.live) { uint64_t next_time = this->start_time + this->elapsed_time; - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 1; + ts.it_value.tv_sec = 0; + ts.it_value.tv_nsec = 1; } - } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; } + spa_system_timerfd_settime(this->data_system, - this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL); + this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &ts, NULL); } } @@ -797,10 +796,6 @@ impl_init(const struct spa_handle_factory *factory, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; if (this->data_loop) spa_loop_add_source(this->data_loop, &this->timer_source); diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index db5c90113..7331edbbd 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -99,7 +99,6 @@ struct impl { bool async; struct spa_source *timer_source; - struct itimerspec timerspec; bool started; uint64_t start_time; @@ -264,20 +263,20 @@ static int fill_buffer(struct impl *this, struct buffer *b) static void set_timer(struct impl *this, bool enabled) { if (this->async || this->props.live) { + struct timespec ts = {0}; + if (enabled) { if (this->props.live) { uint64_t next_time = this->start_time + this->elapsed_time; - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.tv_nsec = next_time % SPA_NSEC_PER_SEC; } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 1; + ts.tv_sec = 0; + ts.tv_nsec = 1; } - } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; } - spa_loop_utils_update_timer(this->loop_utils, this->timer_source, &this->timerspec.it_value, &this->timerspec.it_interval, true); + + spa_loop_utils_update_timer(this->loop_utils, this->timer_source, &ts, NULL, true); } } @@ -907,10 +906,6 @@ impl_init(const struct spa_handle_factory *factory, reset_props(&this->props); this->timer_source = spa_loop_utils_add_timer(this->loop_utils, on_output, this); - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; port = &this->port; port->info_all = SPA_PORT_CHANGE_MASK_FLAGS | diff --git a/spa/plugins/vulkan/vulkan-compute-source.c b/spa/plugins/vulkan/vulkan-compute-source.c index 1daf3b47c..17692636f 100644 --- a/spa/plugins/vulkan/vulkan-compute-source.c +++ b/spa/plugins/vulkan/vulkan-compute-source.c @@ -102,7 +102,6 @@ struct impl { bool async; struct spa_source timer_source; - struct itimerspec timerspec; bool started; uint64_t start_time; @@ -243,21 +242,21 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, static void set_timer(struct impl *this, bool enabled) { if (this->async || this->props.live) { + struct itimerspec ts = {0}; + if (enabled) { if (this->props.live) { uint64_t next_time = this->start_time + this->elapsed_time; - this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; - this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; + ts.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC; + ts.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC; } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 1; + ts.it_value.tv_sec = 0; + ts.it_value.tv_nsec = 1; } - } else { - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; } + spa_system_timerfd_settime(this->data_system, - this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL); + this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &ts, NULL); } } @@ -993,10 +992,6 @@ impl_init(const struct spa_handle_factory *factory, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->timer_source.mask = SPA_IO_IN; this->timer_source.rmask = 0; - this->timerspec.it_value.tv_sec = 0; - this->timerspec.it_value.tv_nsec = 0; - this->timerspec.it_interval.tv_sec = 0; - this->timerspec.it_interval.tv_nsec = 0; if (this->data_loop) spa_loop_add_source(this->data_loop, &this->timer_source);