Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: base/platform_thread_mac.mm

Issue 2774001: posix: set thread names (Closed)
Patch Set: disable linux Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/platform_thread_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_thread_mac.mm
diff --git a/base/platform_thread_mac.mm b/base/platform_thread_mac.mm
index 46ac2416fec28e60edca3c7ffadb3c1abd3013cc..d155b3233e050918a65dc23b3305ca54b0221bc3 100644
--- a/base/platform_thread_mac.mm
+++ b/base/platform_thread_mac.mm
@@ -5,8 +5,10 @@
#include "base/platform_thread.h"
#import <Foundation/Foundation.h>
+#include <dlfcn.h>
#include "base/logging.h"
+#include "base/safe_strerror_posix.h"
// A simple class that demonstrates our impressive ability to do nothing.
@interface NoOp : NSObject
@@ -46,3 +48,22 @@ void InitThreading() {
}
} // namespace base
+
+// static
+void PlatformThread::SetName(const char* name) {
+ // pthread_setname_np is only available in 10.6 or later, so test
+ // for it at runtime.
+ int (*dynamic_pthread_setname_np)(const char*);
+ *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
+ dlsym(RTLD_DEFAULT, "pthread_setname_np");
+ if (!dynamic_pthread_setname_np)
+ return;
+
+ // Mac OS X does not expose the length limit of the name, so
+ // hardcode it.
+ const int kMaxNameLength = 63;
+ std::string shortened_name = std::string(name).substr(0, kMaxNameLength);
+ int err = dynamic_pthread_setname_np(shortened_name.c_str());
+ if (err < 0)
+ LOG(ERROR) << "pthread_setname_np: " << safe_strerror(err);
+}
« no previous file with comments | « no previous file | base/platform_thread_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698