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

Side by Side Diff: src/platform-macos.cc

Issue 6577036: [Isolates] Merge from bleeding_edge to isolates, revisions 6100-6300. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts 28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts
29 // the implementation is in platform-posix.cc. 29 // the implementation is in platform-posix.cc.
30 30
31 #include <dlfcn.h>
31 #include <unistd.h> 32 #include <unistd.h>
32 #include <sys/mman.h> 33 #include <sys/mman.h>
33 #include <mach/mach_init.h> 34 #include <mach/mach_init.h>
34 #include <mach-o/dyld.h> 35 #include <mach-o/dyld.h>
35 #include <mach-o/getsect.h> 36 #include <mach-o/getsect.h>
36 37
37 #include <AvailabilityMacros.h> 38 #include <AvailabilityMacros.h>
38 39
39 #include <pthread.h> 40 #include <pthread.h>
40 #include <semaphore.h> 41 #include <semaphore.h>
41 #include <signal.h> 42 #include <signal.h>
42 #include <libkern/OSAtomic.h> 43 #include <libkern/OSAtomic.h>
43 #include <mach/mach.h> 44 #include <mach/mach.h>
44 #include <mach/semaphore.h> 45 #include <mach/semaphore.h>
45 #include <mach/task.h> 46 #include <mach/task.h>
46 #include <mach/vm_statistics.h> 47 #include <mach/vm_statistics.h>
47 #include <sys/time.h> 48 #include <sys/time.h>
48 #include <sys/resource.h> 49 #include <sys/resource.h>
49 #include <sys/types.h> 50 #include <sys/types.h>
50 #include <stdarg.h> 51 #include <stdarg.h>
51 #include <stdlib.h> 52 #include <stdlib.h>
52
53 #include <errno.h> 53 #include <errno.h>
54 54
55 #undef MAP_TYPE 55 #undef MAP_TYPE
56 56
57 #include "v8.h" 57 #include "v8.h"
58 58
59 #include "platform.h" 59 #include "platform.h"
60 #include "vm-state-inl.h" 60 #include "vm-state-inl.h"
61 61
62 // Manually define these here as weak imports, rather than including execinfo.h. 62 // Manually define these here as weak imports, rather than including execinfo.h.
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 413
414 414
415 bool ThreadHandle::IsValid() const { 415 bool ThreadHandle::IsValid() const {
416 return data_->thread_ != kNoThread; 416 return data_->thread_ != kNoThread;
417 } 417 }
418 418
419 419
420 Thread::Thread(Isolate* isolate) 420 Thread::Thread(Isolate* isolate)
421 : ThreadHandle(ThreadHandle::INVALID), 421 : ThreadHandle(ThreadHandle::INVALID),
422 isolate_(isolate) { 422 isolate_(isolate) {
423 set_name("v8:<unknown>");
424 }
425
426
427 Thread::Thread(Isolate* isolate, const char* name)
428 : ThreadHandle(ThreadHandle::INVALID),
429 isolate_(isolate) {
430 set_name(name);
423 } 431 }
424 432
425 433
426 Thread::~Thread() { 434 Thread::~Thread() {
427 } 435 }
428 436
429 437
438
439 static void SetThreadName(const char* name) {
440 // pthread_setname_np is only available in 10.6 or later, so test
441 // for it at runtime.
442 int (*dynamic_pthread_setname_np)(const char*);
443 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
444 dlsym(RTLD_DEFAULT, "pthread_setname_np");
445 if (!dynamic_pthread_setname_np)
446 return;
447
448 // Mac OS X does not expose the length limit of the name, so hardcode it.
449 static const int kMaxNameLength = 63;
450 USE(kMaxNameLength);
451 ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength);
452 dynamic_pthread_setname_np(name);
453 }
454
455
430 static void* ThreadEntry(void* arg) { 456 static void* ThreadEntry(void* arg) {
431 Thread* thread = reinterpret_cast<Thread*>(arg); 457 Thread* thread = reinterpret_cast<Thread*>(arg);
432 // This is also initialized by the first argument to pthread_create() but we 458 // This is also initialized by the first argument to pthread_create() but we
433 // don't know which thread will run first (the original thread or the new 459 // don't know which thread will run first (the original thread or the new
434 // one) so we initialize it here too. 460 // one) so we initialize it here too.
435 thread->thread_handle_data()->thread_ = pthread_self(); 461 thread->thread_handle_data()->thread_ = pthread_self();
462 SetThreadName(thread->name());
436 ASSERT(thread->IsValid()); 463 ASSERT(thread->IsValid());
437 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 464 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
438 thread->Run(); 465 thread->Run();
439 return NULL; 466 return NULL;
440 } 467 }
441 468
442 469
470 void Thread::set_name(const char* name) {
471 strncpy(name_, name, sizeof(name_));
472 name_[sizeof(name_) - 1] = '\0';
473 }
474
475
443 void Thread::Start() { 476 void Thread::Start() {
444 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); 477 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
445 } 478 }
446 479
447 480
448 void Thread::Join() { 481 void Thread::Join() {
449 pthread_join(thread_handle_data()->thread_, NULL); 482 pthread_join(thread_handle_data()->thread_, NULL);
450 } 483 }
451 484
452 485
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 760
728 void Sampler::Stop() { 761 void Sampler::Stop() {
729 ASSERT(IsActive()); 762 ASSERT(IsActive());
730 SamplerThread::RemoveActiveSampler(this); 763 SamplerThread::RemoveActiveSampler(this);
731 SetActive(false); 764 SetActive(false);
732 } 765 }
733 766
734 #endif // ENABLE_LOGGING_AND_PROFILING 767 #endif // ENABLE_LOGGING_AND_PROFILING
735 768
736 } } // namespace v8::internal 769 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698