diff --git a/daemon/aux.c b/daemon/aux.c index 85fa9ed1d..1d686cd7b 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -303,3 +303,20 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler if (thread_create(thread_detach_func, dt, 1, NULL, name)) abort(); } + +static void thread_looper_helper(void *fp) { + void (*f)(void) = fp; + + while (!rtpe_shutdown) { + gettimeofday(&rtpe_now, NULL); + f(); + + thread_cancel_enable(); + usleep(1000000); /* sleep for 1 second in each iteration */ + thread_cancel_disable(); + } +} + +void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name) { + thread_create_detach_prio(thread_looper_helper, f, scheduler, priority, name); +} diff --git a/daemon/ice.c b/daemon/ice.c index cd727f6ec..ae2c9f050 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -762,20 +762,6 @@ void ice_slow_timer(void) { fragments_cleanup(false); } -/** - * Separate thread for for ice slow timer functionality. - */ -void ice_slow_timer_iterator(void * dummy) { - while (!rtpe_shutdown) { - gettimeofday(&rtpe_now, NULL); - ice_slow_timer(); - - thread_cancel_enable(); - usleep(1000000); /* sleep for 1 second in each iteration */ - thread_cancel_disable(); - } -} - static void __fail_pair(struct ice_candidate_pair *pair) { ilogs(ice, LOG_DEBUG, "Setting ICE candidate pair "PAIR_FORMAT" as failed", PAIR_FMT(pair)); PAIR_SET(pair, FAILED); diff --git a/daemon/main.c b/daemon/main.c index 084263f60..f68bd12e2 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1347,7 +1347,7 @@ int main(int argc, char **argv) { rtpe_config.idle_priority, "load monitor"); /* separate thread for releasing ports (sockets), which are scheduled for clearing */ - thread_create_detach_prio(sockets_releaser, NULL, rtpe_config.idle_scheduling, + thread_create_looper(release_closed_sockets, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "release closed sockets"); /* separate thread for update of running min/max call counters */ @@ -1355,11 +1355,11 @@ int main(int argc, char **argv) { rtpe_config.idle_priority, "call rate stats"); /* separate thread for ports iterations (stats update from the kernel) functionality */ - thread_create_detach_prio(kernel_stats_updater_iterator, NULL, rtpe_config.idle_scheduling, + thread_create_looper(kernel_stats_updater, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "kernel stats updater"); /* separate thread for ice slow timer functionality */ - thread_create_detach_prio(ice_slow_timer_iterator, NULL, rtpe_config.idle_scheduling, + thread_create_looper(ice_slow_timer, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "ice slow timer"); if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 1b8778031..d0c0dea57 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1002,19 +1002,6 @@ void append_thread_lpr_to_glob_lpr(void) { mutex_unlock(&ports_to_release_glob_lock); } -/** - * Separate thread for releasing sockets scheduled for closing. - */ -void sockets_releaser(void * dummy) { - while (!rtpe_shutdown) { - release_closed_sockets(); - - thread_cancel_enable(); - usleep(1000000); /* sleep for 1 second in each iteration */ - thread_cancel_disable(); - } -} - /** * Puts a list of `socket_t` objects into the `out`. * @@ -3340,7 +3327,7 @@ struct interface_stats_block *interface_sampled_rate_stats_get(struct interface_ /** * Ports iterations (stats update from the kernel) functionality. */ -static void kernel_stats_updater(void) { +void kernel_stats_updater(void) { struct rtpengine_list_entry *ke; struct packet_stream *ps; int j; @@ -3507,13 +3494,3 @@ next: } } -void kernel_stats_updater_iterator(void * dummy) { - while (!rtpe_shutdown) { - gettimeofday(&rtpe_now, NULL); - kernel_stats_updater(); - - thread_cancel_enable(); - usleep(1000000); /* sleep for 1 second in each iteration */ - thread_cancel_disable(); - } -} diff --git a/include/aux.h b/include/aux.h index bea02d9f3..06a3a91d5 100644 --- a/include/aux.h +++ b/include/aux.h @@ -327,6 +327,7 @@ void thread_waker_add(struct thread_waker *); void thread_waker_del(struct thread_waker *); void threads_join_all(bool cancel); void thread_create_detach_prio(void (*)(void *), void *, const char *, int, const char *); +void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name); INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) { thread_create_detach_prio(f, a, NULL, 0, name); } diff --git a/include/ice.h b/include/ice.h index 175e7947b..8a4af0fed 100644 --- a/include/ice.h +++ b/include/ice.h @@ -176,8 +176,6 @@ bool trickle_ice_update(struct ng_buffer *ngbuf, struct call *call, struct sdp_n void ice_slow_timer(void); -void ice_slow_timer_iterator(void * dummy); - #include "call.h" diff --git a/include/media_socket.h b/include/media_socket.h index 21eca9d2e..45d911da4 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -300,7 +300,6 @@ struct stream_fd *stream_fd_new(socket_t *fd, struct call *call, struct local_in struct stream_fd *stream_fd_lookup(const endpoint_t *); void stream_fd_release(struct stream_fd *); void release_closed_sockets(void); -void sockets_releaser(void * dummy); void append_thread_lpr_to_glob_lpr(void); void free_intf_list(struct intf_list *il); @@ -334,7 +333,7 @@ const struct transport_protocol *transport_protocol(const str *s); //void play_buffered(struct packet_stream *sink, struct codec_packet *cp, int buffered); void play_buffered(struct jb_packet *cp); -void kernel_stats_updater_iterator(void * dummy); +void kernel_stats_updater(void); INLINE int proto_is_rtp(const struct transport_protocol *protocol) { // known to be RTP? therefore unknown is not RTP