diff options
author | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 17:49:19 +0000 |
---|---|---|
committer | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 17:49:19 +0000 |
commit | fcd37ab325177a976d6e285e27f37771d478a07e (patch) | |
tree | 481425af81970d76094ba747797e86db81a0dad9 | |
parent | 854a485212d5978beb5d58aa9dc122fc138ed2a1 (diff) | |
download | chromium_src-fcd37ab325177a976d6e285e27f37771d478a07e.zip chromium_src-fcd37ab325177a976d6e285e27f37771d478a07e.tar.gz chromium_src-fcd37ab325177a976d6e285e27f37771d478a07e.tar.bz2 |
Simplify thread name setting on Linux
There doesn't seem to be any advantage to supporting the glibc 'pthread_setname_np' function. Relying just on prctl seems sufficient, simpler and should be faster.
This also avoids a memory leak coming from dlsym (perhaps due to a lack of call to dlerror).
BUG=107840
TEST=
Review URL: http://codereview.chromium.org/8965028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115351 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/threading/platform_thread_posix.cc | 32 | ||||
-rw-r--r-- | tools/valgrind/memcheck/suppressions.txt | 7 |
2 files changed, 7 insertions, 32 deletions
diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc index 9b80af4..ea1f037 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -22,7 +22,6 @@ #endif #if defined(OS_LINUX) -#include <dlfcn.h> #include <sys/prctl.h> #include <sys/syscall.h> #include <unistd.h> @@ -182,30 +181,13 @@ void PlatformThread::SetName(const char* name) { return; // http://0pointer.de/blog/projects/name-your-threads.html - - // glibc recently added support for pthread_setname_np, but it's not - // commonly available yet. So test for it at runtime. - int (*dynamic_pthread_setname_np)(pthread_t, const char*); - *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = - dlsym(RTLD_DEFAULT, "pthread_setname_np"); - - if (dynamic_pthread_setname_np) { - // This limit comes from glibc, which gets it from the kernel - // (TASK_COMM_LEN). - const int kMaxNameLength = 15; - std::string shortened_name = std::string(name).substr(0, kMaxNameLength); - int err = dynamic_pthread_setname_np(pthread_self(), - shortened_name.c_str()); - if (err < 0) - DLOG(ERROR) << "pthread_setname_np: " << safe_strerror(err); - } else { - // Implementing this function without glibc is simple enough. (We - // don't do the name length clipping as above because it will be - // truncated by the callee (see TASK_COMM_LEN above).) - int err = prctl(PR_SET_NAME, name); - if (err < 0) - DPLOG(ERROR) << "prctl(PR_SET_NAME)"; - } + // Set the name for the LWP (which gets truncated to 15 characters). + // Note that glibc also has a 'pthread_setname_np' api, but it may not be + // available everywhere and doesn't seem to have any advantage over using + // prctl. + int err = prctl(PR_SET_NAME, name); + if (err < 0) + DPLOG(ERROR) << "prctl(PR_SET_NAME)"; } #elif defined(OS_MACOSX) // Mac is implemented in platform_thread_mac.mm. diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt index 6bb1fdd..f0b0648 100644 --- a/tools/valgrind/memcheck/suppressions.txt +++ b/tools/valgrind/memcheck/suppressions.txt @@ -5191,13 +5191,6 @@ fun:_ZN7WebCore8Document36updateLayoutIgnorePendingStylesheetsEv } { - bug_107840 - Memcheck:Leak - ... - fun:dlsym - fun:_ZN4base14PlatformThread7SetNameEPKc -} -{ bug_108146a Memcheck:Leak fun:_Znw* |