view linux_thread_name.patch @ 0:a9efa2633708

Initial Linnux implementation for set_native_thread_name().
author Roman Kennke <rkennke@redhat.com>
date Tue, 24 Jul 2012 10:09:03 +0200
parents
children
line wrap: on
line source

# HG changeset patch
# Parent dd785aabe02bf33c7a0aac1913d39f4960e7763b

diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp
--- a/src/os/linux/vm/os_linux.cpp
+++ b/src/os/linux/vm/os_linux.cpp
@@ -4344,9 +4344,16 @@
   return online_cpus;
 }
 
+#define MAXTHREADNAMESIZE 16
+
 void os::set_native_thread_name(const char *name) {
-  // Not yet implemented.
-  return;
+  if (name != NULL) {
+    // The maximum length is 16 (including the trailing \0), we copy
+    // the first 15 chars into the buffer.
+    char buf[MAXTHREADNAMESIZE];
+    snprintf(buf, sizeof(buf), "%s", name);
+    pthread_setname_np(pthread_self(), buf);
+  }
 }
 
 bool os::distribute_processes(uint length, uint* distribution) {