Implement mono_threads_core_set_name() on NetBSD (#2914)
authorKamil Rytarowski <krytarowski@users.noreply.github.com>
Mon, 18 Apr 2016 01:55:53 +0000 (03:55 +0200)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 18 Apr 2016 01:55:53 +0000 (21:55 -0400)
Part of man-page showing this interface:

PTHREAD_GETNAME_NP(3)      Library Functions Manual      PTHREAD_GETNAME_NP(3)

NAME
     pthread_getname_np - get and set descriptive name of a thread

LIBRARY
     POSIX Threads Library (libpthread, -lpthread)

SYNOPSIS
     #include <pthread.h>

     int
     pthread_getname_np(pthread_t thread, char *name, size_t len);

     int
     pthread_setname_np(pthread_t thread, const char *name, void *arg);

   -- pthread_setname_np(3)

mono/utils/mono-threads-posix.c

index 7fe86b96273e80ded338c90b945f0dd256646806..395fdb5bdab19dacdf2de564c7e8fa534cd9b936 100644 (file)
@@ -296,6 +296,16 @@ mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
                n [62] = '\0';
                pthread_setname_np (n);
        }
+#elif defined (__NetBSD__)
+       if (!name) {
+               pthread_setname_np (tid, "%s", (void*)"");
+       } else {
+               char n [PTHREAD_MAX_NAMELEN_NP];
+
+               strncpy (n, name, PTHREAD_MAX_NAMELEN_NP);
+               n [PTHREAD_MAX_NAMELEN_NP - 1] = '\0';
+               pthread_setname_np (tid, "%s", (void*)n);
+       }
 #elif defined (HAVE_PTHREAD_SETNAME_NP)
        if (!name) {
                pthread_setname_np (tid, "");