Skip to content

Commit

Permalink
mp_threads: rename threads for consistent naming across all of them
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kasper93 authored and Dudemanguy committed Oct 27, 2023
1 parent 65806ac commit cb82987
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion audio/out/ao_audiotrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion audio/out/ao_wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions filters/f_decoder_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions input/ipc-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");

Expand Down
6 changes: 4 additions & 2 deletions input/ipc-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions osdep/macosx_application.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -377,4 +377,3 @@ int cocoa_main(int argc, char *argv[])
return 1;
}
}

2 changes: 1 addition & 1 deletion osdep/terminal-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion osdep/terminal-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions osdep/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion player/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions player/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions player/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion video/out/w32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit cb82987

Please sign in to comment.