diff --git a/daemon/call.c b/daemon/call.c index 7bfba0997..1a773a3f9 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -318,8 +318,7 @@ static size_t cb_curl_write(char *ptr, size_t size, size_t nmemb, void *userdata return size * nmemb; } -void xmlrpc_kill_calls(void *p) { - struct xmlrpc_helper *xh = p; +void xmlrpc_kill_calls(struct xmlrpc_helper *xh) { unsigned int tries = 0; int els_per_ent = 2; diff --git a/daemon/helpers.c b/daemon/helpers.c index 259fb6f4c..a15b63ae3 100644 --- a/daemon/helpers.c +++ b/daemon/helpers.c @@ -205,8 +205,7 @@ static void thread_detach_cleanup(void *dtp) { thread_join_me(); } -static void *thread_detach_func(void *d) { - struct detach_thread *dt = d; +static void *thread_detach_func(struct detach_thread *dt) { pthread_t *t; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); @@ -267,7 +266,7 @@ static void *thread_detach_func(void *d) { return NULL; } -void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority, +void __thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority, const char *name) { struct detach_thread *dt; @@ -282,9 +281,8 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler abort(); } -static void thread_looper_helper(void *fp) { +static void thread_looper_helper(struct looper_thread *lhp) { // move object to stack and free it, so we can be cancelled without having a leak - struct looper_thread *lhp = fp; struct looper_thread lh = *lhp; g_free(lhp); diff --git a/daemon/main.c b/daemon/main.c index 41619d03a..23e1d153a 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1844,9 +1844,7 @@ static void uring_thread_waker(struct thread_waker *wk) { struct poller *p = wk->arg; uring_poller_wake(p); } -static void uring_poller_loop(void *ptr) { - struct poller *p = ptr; - +static void uring_poller_loop(struct poller *p) { uring_poller_add_waker(p); struct thread_waker wk = {.func = uring_thread_waker, .arg = p}; diff --git a/daemon/media_player.c b/daemon/media_player.c index 5e1362dc4..2d6020a99 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -798,9 +798,7 @@ static void media_player_cache_packet(struct media_player_cache_entry *entry, ch entry->coder.handler->handler_func(entry->coder.handler, &packet); } -static void media_player_cache_entry_decoder_thread(void *p) { - struct media_player_cache_entry *entry = p; - +static void media_player_cache_entry_decoder_thread(struct media_player_cache_entry *entry) { ilog(LOG_DEBUG, "Launching media decoder thread for %s", entry->info_str); while (true) { @@ -913,7 +911,7 @@ static bool media_player_cache_entry_init(struct media_player *mp, const rtp_pay entry->coder.handler->packet_encoded = media_player_packet_cache; // use low priority (10 nice) - thread_create_detach_prio(media_player_cache_entry_decoder_thread, obj_hold(entry), NULL, 10, "mp decoder"); + thread_create_detach_prio(media_player_cache_entry_decoder_thread, obj_get(entry), NULL, 10, "mp decoder"); media_player_cached_reader_start(mp, codec_set); diff --git a/daemon/timerthread.c b/daemon/timerthread.c index c6cca1500..b7703182b 100644 --- a/daemon/timerthread.c +++ b/daemon/timerthread.c @@ -65,8 +65,7 @@ void timerthread_free(struct timerthread *tt) { g_free(tt->threads); } -static void timerthread_run(void *p) { - struct timerthread_thread *tt = p; +static void timerthread_run(struct timerthread_thread *tt) { struct timerthread *parent = tt->parent; struct thread_waker waker = { .lock = &tt->lock, .cond = &tt->cond }; diff --git a/lib/auxlib.c b/lib/auxlib.c index 3b9e1376a..9e092f414 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -73,7 +73,7 @@ void service_notify(const char *message) { } -int thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name) { +int __thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name) { pthread_attr_t att; pthread_t thr; int ret; diff --git a/lib/auxlib.h b/lib/auxlib.h index 0b2565dfd..9e28bc6ee 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -111,7 +111,13 @@ INLINE void config_load(int *argc, char ***argv, GOptionEntry *entries, const ch } char *get_thread_buf(void); -int thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name); +int __thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name); +#define thread_create(func, arg, joinable, handle, name) ({ \ + void *(*__func)(__typeof(arg)) = (func); \ + void *__arg = (arg); \ + int __ret = __thread_create((void *(*)(void *)) __func, __arg, (joinable), (handle), (name)); \ + __ret; \ + }) unsigned int in6_addr_hash(const void *p); int in6_addr_eq(const void *a, const void *b); diff --git a/lib/helpers.h b/lib/helpers.h index f16d87bd0..036e7fdd3 100644 --- a/lib/helpers.h +++ b/lib/helpers.h @@ -214,12 +214,15 @@ void thread_waker_add(struct thread_waker *); void thread_waker_add_generic(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_detach_prio(void (*)(void *), void *, const char *, int, const char *); +#define thread_create_detach_prio(func, arg, sched, prio, name) do { \ + void (*__func)(__typeof(arg)) = (func); \ + void *__arg = (arg); \ + __thread_create_detach_prio((void (*)(void *)) __func, __arg, (sched), (prio), (name)); \ + } while (0) void thread_create_looper(enum thread_looper_action (*f)(void), const char *scheduler, int priority, const char *name, int64_t); -INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) { - thread_create_detach_prio(f, a, NULL, 0, name); -} +#define thread_create_detach(func, arg, name) thread_create_detach_prio(func, arg, NULL, 0, name) diff --git a/lib/poller.c b/lib/poller.c index effe8d04d..7bc61b358 100644 --- a/lib/poller.c +++ b/lib/poller.c @@ -327,8 +327,7 @@ out: return ret; } -void poller_loop(void *d) { - struct poller *p = d; +void poller_loop(struct poller *p) { int poller_size = rtpe_common_config_ptr->poller_size; struct epoll_event *evs; diff --git a/lib/poller.h b/lib/poller.h index 27c96147a..19b2cc09f 100644 --- a/lib/poller.h +++ b/lib/poller.h @@ -45,7 +45,7 @@ void poller_blocked(struct poller *, void *); bool poller_isblocked(struct poller *, void *); void poller_error(struct poller *, void *); -void poller_loop(void *); +void poller_loop(struct poller *); extern bool (*rtpe_poller_add_item)(struct poller *, struct poller_item *); extern bool (*rtpe_poller_del_item)(struct poller *, int); diff --git a/perf-tester/main.c b/perf-tester/main.c index 9a087ca92..db9e4f0c7 100644 --- a/perf-tester/main.c +++ b/perf-tester/main.c @@ -230,7 +230,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, closedir) -static pthread_t thread_new(const char *name, void *(*fn)(void *), void *p) { +static pthread_t __thread_new(const char *name, void *(*fn)(void *), void *p) { pthread_t ret; int s = pthread_create(&ret, NULL, fn, p); if (s != 0) @@ -242,6 +242,13 @@ static pthread_t thread_new(const char *name, void *(*fn)(void *), void *p) { return ret; } +#define thread_new(name, func, arg) ({ \ + void *(*__func)(__typeof(arg)) = (func); \ + void *__arg = (arg); \ + pthread_t __thr = __thread_new((name), (void *(*)(void *)) __func, __arg); \ + __thr; \ + }) + static inline long long us_ticks_scale(long long val) { return val * ticks_per_sec / 1000000; @@ -310,7 +317,7 @@ static int got_frame(decoder_t *decoder, AVFrame *frame, void *p1, void *b) { } -static void *worker(void *p) { +static void *worker(struct worker *p) { thread_cancel_disable(); worker_self = p; worker_self->pid = gettid(); @@ -1771,9 +1778,7 @@ static void delay_measure_workers(uint milliseconds, struct stats *totals) { } -static void *cpu_freq_monitor(void *p) { - struct thread_freq_stats *freq_stats = p; - +static void *cpu_freq_monitor(struct thread_freq_stats *freq_stats) { while (true) { struct freq_stats iter_stats = {0};