diff options
Diffstat (limited to 'osdep')
-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 |
5 files changed, 25 insertions, 0 deletions
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 |