From da719d8b8a2905bf77cd6de78ff966db28cd9d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 6 Aug 2019 13:03:01 +0200 Subject: [PATCH] Add Thread Names --- gui/src/avopenglwidget.cpp | 1 + lib/include/chiaki/thread.h | 1 + lib/src/congestioncontrol.c | 2 ++ lib/src/ctrl.c | 9 ++++++++- lib/src/discovery.c | 2 ++ lib/src/discoveryservice.c | 2 ++ lib/src/feedbacksender.c | 2 ++ lib/src/gkcrypt.c | 2 ++ lib/src/session.c | 6 +++++- lib/src/takion.c | 2 ++ lib/src/takionsendbuffer.c | 2 ++ lib/src/thread.c | 14 ++++++++++++++ 12 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gui/src/avopenglwidget.cpp b/gui/src/avopenglwidget.cpp index 0abb34c..fed5e2b 100644 --- a/gui/src/avopenglwidget.cpp +++ b/gui/src/avopenglwidget.cpp @@ -230,6 +230,7 @@ void AVOpenGLWidget::initializeGL() frame_fg = 0; frame_uploader_thread = new QThread(this); + frame_uploader_thread->setObjectName("Frame Uploader"); frame_uploader_context->moveToThread(frame_uploader_thread); frame_uploader->moveToThread(frame_uploader_thread); frame_uploader_thread->start(); diff --git a/lib/include/chiaki/thread.h b/lib/include/chiaki/thread.h index 4e40a85..5cf13c4 100644 --- a/lib/include/chiaki/thread.h +++ b/lib/include/chiaki/thread.h @@ -37,6 +37,7 @@ typedef void *(*ChiakiThreadFunc)(void *); CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_create(ChiakiThread *thread, ChiakiThreadFunc func, void *arg); CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_join(ChiakiThread *thread, void **retval); +CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_set_name(ChiakiThread *thread, const char *name); typedef struct chiaki_mutex_t diff --git a/lib/src/congestioncontrol.c b/lib/src/congestioncontrol.c index 1b129af..d27c15d 100644 --- a/lib/src/congestioncontrol.c +++ b/lib/src/congestioncontrol.c @@ -59,6 +59,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_start(ChiakiCongestionCo return err; } + chiaki_thread_set_name(&control->thread, "Chiaki Congestion Control"); + return CHIAKI_ERR_SUCCESS; } diff --git a/lib/src/ctrl.c b/lib/src/ctrl.c index 8d6bf74..5400a77 100644 --- a/lib/src/ctrl.c +++ b/lib/src/ctrl.c @@ -47,7 +47,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_ctrl_start(ChiakiCtrl *ctrl, ChiakiSession ChiakiErrorCode err = chiaki_stop_pipe_init(&ctrl->stop_pipe); if(err != CHIAKI_ERR_SUCCESS) return err; - return chiaki_thread_create(&ctrl->thread, ctrl_thread_func, ctrl); + err = chiaki_thread_create(&ctrl->thread, ctrl_thread_func, ctrl); + if(err != CHIAKI_ERR_SUCCESS) + { + chiaki_stop_pipe_fini(&ctrl->stop_pipe); + return err; + } + chiaki_thread_set_name(&ctrl->thread, "Chiaki Ctrl"); + return err; } CHIAKI_EXPORT void chiaki_ctrl_stop(ChiakiCtrl *ctrl) diff --git a/lib/src/discovery.c b/lib/src/discovery.c index 379ba92..b6246d0 100644 --- a/lib/src/discovery.c +++ b/lib/src/discovery.c @@ -128,6 +128,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThrea return err; } + chiaki_thread_set_name(&thread->thread, "Chiaki Discovery"); + return CHIAKI_ERR_SUCCESS; } diff --git a/lib/src/discoveryservice.c b/lib/src/discoveryservice.c index 21733cd..7ef467e 100644 --- a/lib/src/discoveryservice.c +++ b/lib/src/discoveryservice.c @@ -45,6 +45,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_service_init(ChiakiDiscoveryServi if(err != CHIAKI_ERR_SUCCESS) goto error_stop_cond; + chiaki_thread_set_name(&service->thread, "Chiaki Discovery Service"); + return CHIAKI_ERR_SUCCESS; error_stop_cond: chiaki_bool_pred_cond_fini(&service->stop_cond); diff --git a/lib/src/feedbacksender.c b/lib/src/feedbacksender.c index 8b8d20d..667e10b 100644 --- a/lib/src/feedbacksender.c +++ b/lib/src/feedbacksender.c @@ -51,6 +51,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_sender_init(ChiakiFeedbackSender * if(err != CHIAKI_ERR_SUCCESS) goto error_cond; + chiaki_thread_set_name(&feedback_sender->thread, "Chiaki Feedback Sender"); + return CHIAKI_ERR_SUCCESS; error_cond: chiaki_cond_fini(&feedback_sender->state_cond); diff --git a/lib/src/gkcrypt.c b/lib/src/gkcrypt.c index c43c47c..b58c914 100644 --- a/lib/src/gkcrypt.c +++ b/lib/src/gkcrypt.c @@ -86,6 +86,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_init(ChiakiGKCrypt *gkcrypt, Chiaki err = chiaki_thread_create(&gkcrypt->key_buf_thread, gkcrypt_thread_func, gkcrypt); if(err != CHIAKI_ERR_SUCCESS) goto error_key_buf_cond; + + chiaki_thread_set_name(&gkcrypt->key_buf_thread, "Chiaki GKCrypt"); } return CHIAKI_ERR_SUCCESS; diff --git a/lib/src/session.c b/lib/src/session.c index d116189..5c293ff 100644 --- a/lib/src/session.c +++ b/lib/src/session.c @@ -200,7 +200,11 @@ CHIAKI_EXPORT void chiaki_session_fini(ChiakiSession *session) CHIAKI_EXPORT ChiakiErrorCode chiaki_session_start(ChiakiSession *session) { - return chiaki_thread_create(&session->session_thread, session_thread_func, session); + ChiakiErrorCode err = chiaki_thread_create(&session->session_thread, session_thread_func, session); + if(err != CHIAKI_ERR_SUCCESS) + return err; + chiaki_thread_set_name(&session->session_thread, "Chiaki Session"); + return err; } CHIAKI_EXPORT ChiakiErrorCode chiaki_session_stop(ChiakiSession *session) diff --git a/lib/src/takion.c b/lib/src/takion.c index 47f7f97..9b81272 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -239,6 +239,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki goto error_sock; } + chiaki_thread_set_name(&takion->thread, "Chiaki Takion"); + return CHIAKI_ERR_SUCCESS; error_sock: diff --git a/lib/src/takionsendbuffer.c b/lib/src/takionsendbuffer.c index c54f8dc..90086e6 100644 --- a/lib/src/takionsendbuffer.c +++ b/lib/src/takionsendbuffer.c @@ -68,6 +68,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_init(ChiakiTakionSendBuf if(err != CHIAKI_ERR_SUCCESS) goto error_cond; + chiaki_thread_set_name(&send_buffer->thread, "Chiaki Takion Send Buffer"); + return CHIAKI_ERR_SUCCESS; error_cond: chiaki_cond_fini(&send_buffer->cond); diff --git a/lib/src/thread.c b/lib/src/thread.c index 8ce5fd8..35eca17 100644 --- a/lib/src/thread.c +++ b/lib/src/thread.c @@ -15,12 +15,15 @@ * along with Chiaki. If not, see . */ +#define _GNU_SOURCE + #include #include #include #include +#include CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_create(ChiakiThread *thread, ChiakiThreadFunc func, void *arg) { @@ -38,6 +41,17 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_join(ChiakiThread *thread, void **re return CHIAKI_ERR_SUCCESS; } +CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_set_name(ChiakiThread *thread, const char *name) +{ +#ifdef __GLIBC__ + int r = pthread_setname_np(thread->thread, name); + if(r != 0) + return CHIAKI_ERR_THREAD; +#else + (void)thread; (void)name; +#endif + return CHIAKI_ERR_SUCCESS; +} CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex, bool rec)