src/os/linux/vm/os_linux.cpp

changeset 9676
bf1c9a3312a4
parent 9620
97d605522fcb
child 9703
2fdf635bcf28
child 9711
0f2fe7d37d8c
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Fri May 17 07:44:31 2019 +0100
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Mon Oct 13 22:11:39 2014 +0200
     1.3 @@ -136,6 +136,7 @@
     1.4  
     1.5  int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL;
     1.6  int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
     1.7 +int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
     1.8  Mutex* os::Linux::_createThread_lock = NULL;
     1.9  pthread_t os::Linux::_main_thread;
    1.10  int os::Linux::_page_size = -1;
    1.11 @@ -5054,6 +5055,11 @@
    1.12      StackRedPages = 1;
    1.13      StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
    1.14    }
    1.15 +
    1.16 +  // retrieve entry point for pthread_setname_np
    1.17 +  Linux::_pthread_setname_np =
    1.18 +    (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
    1.19 +
    1.20  }
    1.21  
    1.22  // To install functions for atexit system call
    1.23 @@ -5308,8 +5314,14 @@
    1.24  }
    1.25  
    1.26  void os::set_native_thread_name(const char *name) {
    1.27 -  // Not yet implemented.
    1.28 -  return;
    1.29 +  if (Linux::_pthread_setname_np) {
    1.30 +    char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
    1.31 +    snprintf(buf, sizeof(buf), "%s", name);
    1.32 +    buf[sizeof(buf) - 1] = '\0';
    1.33 +    const int rc = Linux::_pthread_setname_np(pthread_self(), buf);
    1.34 +    // ERANGE should not happen; all other errors should just be ignored.
    1.35 +    assert(rc != ERANGE, "pthread_setname_np failed");
    1.36 +  }
    1.37  }
    1.38  
    1.39  bool os::distribute_processes(uint length, uint* distribution) {

mercurial