osdep: shorten thread name on glibc only

Instead of affecting every platform, do this for glibc only (where it's
known to be a problem), and only if the right error is returned.
This commit is contained in:
wm4 2014-10-20 21:50:49 +02:00
parent c918b8a3f3
commit d38e36b98f
1 changed files with 7 additions and 3 deletions

View File

@ -15,6 +15,7 @@
* with mpv. If not, see <http://www.gnu.org/licenses/>. * with mpv. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "config.h" #include "config.h"
@ -46,10 +47,13 @@ int mpthread_mutex_init_recursive(pthread_mutex_t *mutex)
void mpthread_set_name(const char *name) void mpthread_set_name(const char *name)
{ {
char tname[16]; char tname[80];
snprintf(tname, sizeof(tname), "mpv %s", name); snprintf(tname, sizeof(tname), "mpv/%s", name);
#if HAVE_GLIBC_THREAD_NAME #if HAVE_GLIBC_THREAD_NAME
pthread_setname_np(pthread_self(), tname); if (pthread_setname_np(pthread_self(), tname) == ERANGE) {
tname[15] = '\0'; // glibc-checked kernel limit
pthread_setname_np(pthread_self(), tname);
}
#elif HAVE_BSD_THREAD_NAME #elif HAVE_BSD_THREAD_NAME
pthread_set_name_np(pthread_self(), tname); pthread_set_name_np(pthread_self(), tname);
#elif HAVE_OSX_THREAD_NAME #elif HAVE_OSX_THREAD_NAME