| Index: src/platform-macos.cc
|
| ===================================================================
|
| --- src/platform-macos.cc (revision 6941)
|
| +++ src/platform-macos.cc (working copy)
|
| @@ -28,6 +28,7 @@
|
| // Platform specific code for MacOS goes here. For the POSIX comaptible parts
|
| // the implementation is in platform-posix.cc.
|
|
|
| +#include <dlfcn.h>
|
| #include <unistd.h>
|
| #include <sys/mman.h>
|
| #include <mach/mach_init.h>
|
| @@ -49,7 +50,6 @@
|
| #include <sys/types.h>
|
| #include <stdarg.h>
|
| #include <stdlib.h>
|
| -
|
| #include <errno.h>
|
|
|
| #undef MAP_TYPE
|
| @@ -420,19 +420,46 @@
|
| Thread::Thread(Isolate* isolate)
|
| : ThreadHandle(ThreadHandle::INVALID),
|
| isolate_(isolate) {
|
| + set_name("v8:<unknown>");
|
| }
|
|
|
|
|
| +Thread::Thread(Isolate* isolate, const char* name)
|
| + : ThreadHandle(ThreadHandle::INVALID),
|
| + isolate_(isolate) {
|
| + set_name(name);
|
| +}
|
| +
|
| +
|
| Thread::~Thread() {
|
| }
|
|
|
|
|
| +
|
| +static void SetThreadName(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.
|
| + static const int kMaxNameLength = 63;
|
| + USE(kMaxNameLength);
|
| + ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength);
|
| + dynamic_pthread_setname_np(name);
|
| +}
|
| +
|
| +
|
| static void* ThreadEntry(void* arg) {
|
| Thread* thread = reinterpret_cast<Thread*>(arg);
|
| // This is also initialized by the first argument to pthread_create() but we
|
| // don't know which thread will run first (the original thread or the new
|
| // one) so we initialize it here too.
|
| thread->thread_handle_data()->thread_ = pthread_self();
|
| + SetThreadName(thread->name());
|
| ASSERT(thread->IsValid());
|
| Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
|
| thread->Run();
|
| @@ -440,6 +467,12 @@
|
| }
|
|
|
|
|
| +void Thread::set_name(const char* name) {
|
| + strncpy(name_, name, sizeof(name_));
|
| + name_[sizeof(name_) - 1] = '\0';
|
| +}
|
| +
|
| +
|
| void Thread::Start() {
|
| pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
|
| }
|
|
|