mp_threads: rename threads for consistent naming across all of them

I'd like some names to be more descriptive, but to work with 15 chars
limit we have to make some sacrifice.

Also because of the limit, remove the `mpv/` prefix and prioritize
actuall thread name.
This commit is contained in:
Kacper Michajłow 2023-10-22 20:59:34 +02:00 committed by Dudemanguy
parent 65806ac4d1
commit cb829879af
15 changed files with 30 additions and 26 deletions

View File

@ -554,7 +554,7 @@ static void *playthread(void *arg)
struct ao *ao = arg;
struct priv *p = ao->priv;
JNIEnv *env = MP_JNI_GET_ENV(ao);
mpthread_set_name("audiotrack");
mpthread_set_name("ao/audiotrack");
pthread_mutex_lock(&p->lock);
while (!p->thread_terminate) {
int state = AudioTrack.PLAYSTATE_PAUSED;

View File

@ -199,7 +199,7 @@ static DWORD __stdcall AudioThread(void *lpParameter)
{
struct ao *ao = lpParameter;
struct wasapi_state *state = ao->priv;
mpthread_set_name("wasapi event");
mpthread_set_name("ao/wasapi");
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
state->init_ok = wasapi_thread_init(ao);

View File

@ -541,7 +541,7 @@ static void *log_file_thread(void *p)
{
struct mp_log_root *root = p;
mpthread_set_name("log-file");
mpthread_set_name("log");
pthread_mutex_lock(&root->log_file_lock);

View File

@ -1102,10 +1102,10 @@ static void *dec_thread(void *ptr)
{
struct priv *p = ptr;
char *t_name = "?";
char *t_name = "dec/?";
switch (p->header->type) {
case STREAM_VIDEO: t_name = "vdec"; break;
case STREAM_AUDIO: t_name = "adec"; break;
case STREAM_VIDEO: t_name = "dec/video"; break;
case STREAM_AUDIO: t_name = "dec/audio"; break;
}
mpthread_set_name(t_name);

View File

@ -1622,7 +1622,7 @@ static void *input_src_thread(void *ptr)
void (*loop_fn)(struct mp_input_src *src, void *ctx) = args[1];
void *ctx = args[2];
mpthread_set_name("input source");
mpthread_set_name("input");
src->in->thread_running = true;

View File

@ -105,7 +105,9 @@ static void *client_thread(void *p)
struct client_arg *arg = p;
bstr client_msg = { talloc_strdup(NULL, ""), 0 };
mpthread_set_name(arg->client_name);
char *tname = talloc_asprintf(NULL, "ipc/%s", arg->client_name);
mpthread_set_name(tname);
talloc_free(tname);
int pipe_fd = mpv_get_wakeup_pipe(arg->client);
if (pipe_fd < 0) {
@ -302,7 +304,7 @@ static void *ipc_thread(void *p)
struct mp_ipc_ctx *arg = p;
mpthread_set_name("ipc socket listener");
mpthread_set_name("ipc/socket");
MP_VERBOSE(arg, "Starting IPC master\n");

View File

@ -210,7 +210,9 @@ static void *client_thread(void *p)
DWORD ioerr = 0;
DWORD r;
mpthread_set_name(arg->client_name);
char *tname = talloc_asprintf(NULL, "ipc/%s", arg->client_name);
mpthread_set_name(tname);
talloc_free(tname);
arg->write_ol.hEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
if (!wakeup_event || !ol.hEvent || !arg->write_ol.hEvent) {
@ -356,7 +358,7 @@ static void *ipc_thread(void *p)
HANDLE client = INVALID_HANDLE_VALUE;
int client_num = 0;
mpthread_set_name("ipc named pipe listener");
mpthread_set_name("ipc/named-pipe");
MP_VERBOSE(arg, "Starting IPC master\n");
SECURITY_ATTRIBUTES sa = {

View File

@ -275,7 +275,7 @@ static void cocoa_run_runloop(void)
static void *playback_thread(void *ctx_obj)
{
mpthread_set_name("playback core (OSX)");
mpthread_set_name("core/playback");
@autoreleasepool {
struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj;
int r = mpv_main(*ctx->argc, *ctx->argv);
@ -377,4 +377,3 @@ int cocoa_main(int argc, char *argv[])
return 1;
}
}

View File

@ -408,7 +408,7 @@ static void quit_request_sighandler(int signum)
static void *terminal_thread(void *ptr)
{
mpthread_set_name("terminal");
mpthread_set_name("terminal/input");
bool stdin_ok = read_terminal; // if false, we still wait for SIGTERM
while (1) {
getch2_poll();

View File

@ -161,7 +161,7 @@ static void read_input(HANDLE in)
static void *input_thread_fn(void *ptr)
{
mpthread_set_name("terminal");
mpthread_set_name("terminal/input");
HANDLE in = ptr;
HANDLE stuff[2] = {in, death};
while (1) {

View File

@ -40,17 +40,16 @@ int mpthread_mutex_init_recursive(pthread_mutex_t *mutex)
void mpthread_set_name(const char *name)
{
char tname[80];
snprintf(tname, sizeof(tname), "mpv/%s", name);
#if HAVE_GLIBC_THREAD_NAME
if (pthread_setname_np(pthread_self(), tname) == ERANGE) {
tname[15] = '\0'; // glibc-checked kernel limit
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
char tname[16] = {0}; // glibc-checked kernel limit
strncpy(tname, name, sizeof(tname) - 1);
pthread_setname_np(pthread_self(), tname);
}
#elif HAVE_WIN32_INTERNAL_PTHREADS || HAVE_BSD_THREAD_NAME
pthread_set_name_np(pthread_self(), tname);
pthread_set_name_np(pthread_self(), name);
#elif HAVE_OSX_THREAD_NAME
pthread_setname_np(tname);
pthread_setname_np(name);
#endif
}

View File

@ -602,7 +602,7 @@ static void *core_thread(void *p)
{
struct MPContext *mpctx = p;
mpthread_set_name("mpv core");
mpthread_set_name("core");
while (!mpctx->initialized && mpctx->stop_play != PT_QUIT)
mp_idle(mpctx);

View File

@ -34,6 +34,7 @@
#include "misc/thread_pool.h"
#include "osdep/io.h"
#include "osdep/terminal.h"
#include "osdep/threads.h"
#include "osdep/timer.h"
#include "osdep/main-fn.h"
@ -419,6 +420,7 @@ int mp_initialize(struct MPContext *mpctx, char **options)
int mpv_main(int argc, char *argv[])
{
mpthread_set_name("main");
struct MPContext *mpctx = mp_create();
if (!mpctx)
return 1;

View File

@ -85,10 +85,10 @@ static char *script_name_from_filename(void *talloc_ctx, const char *fname)
static void run_script(struct mp_script_args *arg)
{
char name[90];
snprintf(name, sizeof(name), "%s (%s)", arg->backend->name,
mpv_client_name(arg->client));
char *name = talloc_asprintf(NULL, "%s/%s", arg->backend->name,
mpv_client_name(arg->client));
mpthread_set_name(name);
talloc_free(name);
if (arg->backend->load(arg) < 0)
MP_ERR(arg, "Could not load %s %s\n", arg->backend->name, arg->filename);

View File

@ -1730,7 +1730,7 @@ static void *gui_thread(void *ptr)
bool ole_ok = false;
int res = 0;
mpthread_set_name("win32 window");
mpthread_set_name("window");
w32_api_load(w32);