diff options
-rw-r--r-- | audio/out/push.c | 1 | ||||
-rw-r--r-- | demux/demux.c | 2 | ||||
-rw-r--r-- | input/input.c | 2 | ||||
-rw-r--r-- | input/ipc.c | 5 | ||||
-rwxr-xr-x | old-configure | 3 | ||||
-rw-r--r-- | osdep/macosx_application.m | 2 | ||||
-rw-r--r-- | osdep/terminal-unix.c | 2 | ||||
-rw-r--r-- | osdep/terminal-win.c | 2 | ||||
-rw-r--r-- | osdep/threads.c | 16 | ||||
-rw-r--r-- | osdep/threads.h | 3 | ||||
-rw-r--r-- | player/client.c | 2 | ||||
-rw-r--r-- | player/misc.c | 2 | ||||
-rw-r--r-- | player/scripting.c | 5 | ||||
-rw-r--r-- | stream/cache.c | 1 | ||||
-rw-r--r-- | video/out/vo.c | 3 | ||||
-rw-r--r-- | video/out/w32_common.c | 3 | ||||
-rw-r--r-- | wscript | 19 |
17 files changed, 73 insertions, 0 deletions
diff --git a/audio/out/push.c b/audio/out/push.c index 20337ef9d2..187d5ef03a 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -303,6 +303,7 @@ static void *playthread(void *arg) { struct ao *ao = arg; struct ao_push_state *p = ao->api_priv; + mpthread_set_name("ao"); pthread_mutex_lock(&p->lock); while (!p->terminate) { if (!p->paused) diff --git a/demux/demux.c b/demux/demux.c index 6f226d8737..e5cd4d53fe 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -33,6 +33,7 @@ #include "talloc.h" #include "common/msg.h" #include "common/global.h" +#include "osdep/threads.h" #include "stream/stream.h" #include "demux.h" @@ -455,6 +456,7 @@ static void execute_seek(struct demux_internal *in) static void *demux_thread(void *pctx) { struct demux_internal *in = pctx; + mpthread_set_name("demux"); pthread_mutex_lock(&in->lock); while (!in->thread_terminate) { in->thread_paused = in->thread_request_pause > 0; diff --git a/input/input.c b/input/input.c index c9a5bbe99c..cfb41342cd 100644 --- a/input/input.c +++ b/input/input.c @@ -1451,6 +1451,8 @@ 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"); + src->in->thread_running = true; loop_fn(src, ctx); diff --git a/input/ipc.c b/input/ipc.c index a64be27de3..0fc6208faa 100644 --- a/input/ipc.c +++ b/input/ipc.c @@ -29,6 +29,7 @@ #include "config.h" #include "osdep/io.h" +#include "osdep/threads.h" #include "common/common.h" #include "common/global.h" @@ -471,6 +472,8 @@ static void *client_thread(void *p) struct client_arg *arg = p; bstr client_msg = { talloc_strdup(NULL, ""), 0 }; + mpthread_set_name(arg->client_name); + int pipe_fd = mpv_get_wakeup_pipe(arg->client); if (pipe_fd < 0) { MP_ERR(arg, "Could not get wakeup pipe\n"); @@ -649,6 +652,8 @@ static void *ipc_thread(void *p) struct mp_ipc_ctx *arg = p; + mpthread_set_name("ipc socket listener"); + MP_INFO(arg, "Starting IPC master\n"); ipc_fd = socket(AF_UNIX, SOCK_STREAM, 0); diff --git a/old-configure b/old-configure index 26fee13711..0d1ff4cb17 100755 --- a/old-configure +++ b/old-configure @@ -990,6 +990,9 @@ cat > $TMPC << EOF #define HAVE_SDL1 0 #define HAVE_WAIO 0 #define HAVE_POSIX_SPAWN 1 +#define HAVE_GLIBC_THREAD_NAME (!!__GLIBC__) +#define HAVE_OSX_THREAD_NAME 0 +#define HAVE_BSD_THREAD_NAME 0 #define DEFAULT_CDROM_DEVICE "/dev/cdrom" #define DEFAULT_DVD_DEVICE "/dev/dvd" diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 9b62eb68b2..37c3d40773 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -26,6 +26,7 @@ #import "osdep/macosx_application_objc.h" #include "osdep/macosx_compat.h" #import "osdep/macosx_events_objc.h" +#include "osdep/threads.h" #define MPV_PROTOCOL @"mpv://" @@ -283,6 +284,7 @@ struct playback_thread_ctx { static void *playback_thread(void *ctx_obj) { + mpthread_set_name("playback core (OSX)"); @autoreleasepool { struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj; ctx->mpv_main(*ctx->argc, *ctx->argv); diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index bb5ae324ff..f17524c0f1 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -45,6 +45,7 @@ #include <poll.h> #include "osdep/io.h" +#include "osdep/threads.h" #include "common/common.h" #include "misc/bstr.h" @@ -757,6 +758,7 @@ static void quit_request_sighandler(int signum) static void *terminal_thread(void *ptr) { + mpthread_set_name("terminal"); bool stdin_ok = isatty(STDIN_FILENO); // if false, we still wait for SIGTERM while (1) { struct pollfd fds[2] = { diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index 9bfb97041b..678cedb775 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -37,6 +37,7 @@ #include "input/input.h" #include "terminal.h" #include "osdep/io.h" +#include "osdep/threads.h" #include "osdep/w32_keyboard.h" #define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE) @@ -122,6 +123,7 @@ static void read_input(void) static void *input_thread_fn(void *ptr) { + mpthread_set_name("terminal"); HANDLE in = GetStdHandle(STD_INPUT_HANDLE); HANDLE stuff[2] = {in, death}; while (1) { diff --git a/osdep/threads.c b/osdep/threads.c index 8cb03045e4..c41007b2cb 100644 --- a/osdep/threads.c +++ b/osdep/threads.c @@ -14,6 +14,9 @@ * You should have received a copy of the GNU General Public License along * with mpv. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdio.h> + +#include "config.h" #include "threads.h" #include "timer.h" @@ -40,3 +43,16 @@ int mpthread_mutex_init_recursive(pthread_mutex_t *mutex) pthread_mutexattr_destroy(&attr); return r; } + +void mpthread_set_name(const char *name) +{ + char tname[90]; + snprintf(tname, sizeof(tname), "mpv %s", name); +#if HAVE_GLIBC_THREAD_NAME + pthread_setname_np(pthread_self(), tname); +#elif HAVE_BSD_THREAD_NAME + pthread_set_name_np(pthread_self(), tname); +#elif HAVE_OSX_THREAD_NAME + pthread_setname_np(tname); +#endif +} diff --git a/osdep/threads.h b/osdep/threads.h index fa9199d63d..2277fa65a1 100644 --- a/osdep/threads.h +++ b/osdep/threads.h @@ -16,4 +16,7 @@ int mpthread_cond_timedwait_rel(pthread_cond_t *cond, pthread_mutex_t *mutex, // Helper to reduce boiler plate. int mpthread_mutex_init_recursive(pthread_mutex_t *mutex); +// Set thread name (for debuggers). +void mpthread_set_name(const char *name); + #endif diff --git a/player/client.c b/player/client.c index 2166255c2c..17d315bc1d 100644 --- a/player/client.c +++ b/player/client.c @@ -419,6 +419,8 @@ static void *playback_thread(void *p) struct MPContext *mpctx = p; mpctx->autodetach = true; + mpthread_set_name("playback core"); + mp_play_files(mpctx); // This actually waits until all clients are gone before actually diff --git a/player/misc.c b/player/misc.c index 21e9bcbba3..81b80a1948 100644 --- a/player/misc.c +++ b/player/misc.c @@ -26,6 +26,7 @@ #include "osdep/io.h" #include "osdep/timer.h" +#include "osdep/threads.h" #include "common/msg.h" #include "options/options.h" @@ -249,6 +250,7 @@ struct wrapper_args { static void *thread_wrapper(void *pctx) { struct wrapper_args *args = pctx; + mpthread_set_name("opener"); args->thread_fn(args->thread_arg); pthread_mutex_lock(&args->mutex); args->done = true; diff --git a/player/scripting.c b/player/scripting.c index 5bc9a915f3..935bbd0490 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -26,6 +26,7 @@ #include "config.h" #include "osdep/io.h" +#include "osdep/threads.h" #include "common/common.h" #include "common/msg.h" @@ -78,6 +79,10 @@ static void *script_thread(void *p) struct thread_arg *arg = p; + char name[90]; + snprintf(name, sizeof(name), "script (%s)", arg->fname); + mpthread_set_name(name); + if (arg->backend->load(arg->client, arg->fname) < 0) MP_ERR(arg, "Could not load script %s\n", arg->fname); diff --git a/stream/cache.c b/stream/cache.c index a5ac1c2995..bc4d9e2610 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -457,6 +457,7 @@ static void cache_execute_control(struct priv *s) static void *cache_thread(void *arg) { struct priv *s = arg; + mpthread_set_name("cache"); pthread_mutex_lock(&s->mutex); update_cached_controls(s); double last = mp_time_sec(); diff --git a/video/out/vo.c b/video/out/vo.c index fcc15e4008..9f6021282f 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -47,6 +47,7 @@ #include "video/vfcap.h" #include "sub/osd.h" #include "osdep/io.h" +#include "osdep/threads.h" extern const struct vo_driver video_out_x11; extern const struct vo_driver video_out_vdpau; @@ -666,6 +667,8 @@ static void *vo_thread(void *ptr) struct vo *vo = ptr; struct vo_internal *in = vo->in; + mpthread_set_name("vo"); + int r = vo->driver->preinit(vo) ? -1 : 0; mp_rendezvous(vo, r); // init barrier if (r < 0) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 541000a7f9..600aa26716 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -34,6 +34,7 @@ #include "win_state.h" #include "w32_common.h" #include "osdep/io.h" +#include "osdep/threads.h" #include "osdep/w32_keyboard.h" #include "misc/dispatch.h" #include "misc/rendezvous.h" @@ -990,6 +991,8 @@ static void *gui_thread(void *ptr) bool ole_ok = false; int res = 0; + mpthread_set_name("win32 window"); + HINSTANCE hInstance = GetModuleHandleW(NULL); WNDCLASSEXW wcex = { @@ -212,6 +212,25 @@ iconv support use --disable-iconv.", 'deps_any': [ 'os-win32', 'os-cygwin' ], 'func': check_true }, { + 'name': 'glibc-thread-name', + 'desc': 'GLIBC API for setting thread name', + 'func': check_statement('pthread.h', + 'pthread_setname_np(pthread_self(), "ducks")', + use=['pthreads']), + }, { + 'name': 'osx-thread-name', + 'desc': 'OSX API for setting thread name', + 'deps_neg': [ 'glibc-thread-name' ], + 'func': check_statement('pthread.h', + 'pthread_setname_np("ducks")', use=['pthreads']), + }, { + 'name': 'bsd-thread-name', + 'desc': 'BSD API for setting thread name', + 'deps_neg': [ 'glibc-thread-name', 'osx-thread-name' ], + 'func': check_statement('pthread.h', + 'pthread_set_name_np(pthread_self(), "ducks")', + use=['pthreads']), + }, { 'name': 'bsd-fstatfs', 'desc': "BSD's fstatfs()", 'func': check_statement(['sys/param.h', 'sys/mount.h'], |