Add Thread Names

This commit is contained in:
Florian Märkl 2019-08-06 13:03:01 +02:00
commit da719d8b8a
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
12 changed files with 43 additions and 2 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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)

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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)

View file

@ -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:

View file

@ -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);

View file

@ -15,12 +15,15 @@
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <chiaki/thread.h>
#include <chiaki/time.h>
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
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)