| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // If you don't have execinfo.h then you need devel/libexecinfo from ports. | 45 // If you don't have execinfo.h then you need devel/libexecinfo from ports. |
| 46 #include <execinfo.h> // backtrace, backtrace_symbols | 46 #include <execinfo.h> // backtrace, backtrace_symbols |
| 47 #include <strings.h> // index | 47 #include <strings.h> // index |
| 48 #include <errno.h> | 48 #include <errno.h> |
| 49 #include <stdarg.h> | 49 #include <stdarg.h> |
| 50 #include <limits.h> | 50 #include <limits.h> |
| 51 | 51 |
| 52 #undef MAP_TYPE | 52 #undef MAP_TYPE |
| 53 | 53 |
| 54 #include "v8.h" | 54 #include "v8.h" |
| 55 #include "v8threads.h" |
| 55 | 56 |
| 56 #include "platform.h" | 57 #include "platform.h" |
| 57 #include "vm-state-inl.h" | 58 #include "vm-state-inl.h" |
| 58 | 59 |
| 59 | 60 |
| 60 namespace v8 { | 61 namespace v8 { |
| 61 namespace internal { | 62 namespace internal { |
| 62 | 63 |
| 63 // 0 is never a valid thread id on FreeBSD since tids and pids share a | 64 // 0 is never a valid thread id on FreeBSD since tids and pids share a |
| 64 // name space and pid 0 is used to kill the group (see man 2 kill). | 65 // name space and pid 0 is used to kill the group (see man 2 kill). |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 kMmapFd, kMmapFdOffset) != MAP_FAILED; | 391 kMmapFd, kMmapFdOffset) != MAP_FAILED; |
| 391 } | 392 } |
| 392 | 393 |
| 393 | 394 |
| 394 class Thread::PlatformData : public Malloced { | 395 class Thread::PlatformData : public Malloced { |
| 395 public: | 396 public: |
| 396 pthread_t thread_; // Thread handle for pthread. | 397 pthread_t thread_; // Thread handle for pthread. |
| 397 }; | 398 }; |
| 398 | 399 |
| 399 | 400 |
| 400 ThreadHandle::ThreadHandle(Kind kind) { | |
| 401 data_ = new PlatformData(kind); | |
| 402 } | |
| 403 | |
| 404 | |
| 405 void ThreadHandle::Initialize(ThreadHandle::Kind kind) { | |
| 406 data_->Initialize(kind); | |
| 407 } | |
| 408 | |
| 409 | |
| 410 ThreadHandle::~ThreadHandle() { | |
| 411 delete data_; | |
| 412 } | |
| 413 | |
| 414 | |
| 415 bool ThreadHandle::IsSelf() const { | |
| 416 return pthread_equal(data_->thread_, pthread_self()); | |
| 417 } | |
| 418 | |
| 419 | |
| 420 bool ThreadHandle::IsValid() const { | |
| 421 return data_->thread_ != kNoThread; | |
| 422 } | |
| 423 | |
| 424 | |
| 425 Thread::Thread(Isolate* isolate, const Options& options) | 401 Thread::Thread(Isolate* isolate, const Options& options) |
| 426 : data_(new PlatformData), | 402 : data_(new PlatformData), |
| 427 isolate_(isolate), | 403 isolate_(isolate), |
| 428 stack_size_(options.stack_size) { | 404 stack_size_(options.stack_size) { |
| 429 set_name(options.name); | 405 set_name(options.name); |
| 430 } | 406 } |
| 431 | 407 |
| 432 | 408 |
| 433 Thread::Thread(Isolate* isolate, const char* name) | 409 Thread::Thread(Isolate* isolate, const char* name) |
| 434 : data_(new PlatformData), | 410 : data_(new PlatformData), |
| 435 isolate_(isolate), | 411 isolate_(isolate), |
| 436 stack_size_(0) { | 412 stack_size_(0) { |
| 437 set_name(name); | 413 set_name(name); |
| 438 } | 414 } |
| 439 | 415 |
| 440 | 416 |
| 441 Thread::~Thread() { | 417 Thread::~Thread() { |
| 442 delete data_; | 418 delete data_; |
| 443 } | 419 } |
| 444 | 420 |
| 445 | 421 |
| 446 static void* ThreadEntry(void* arg) { | 422 static void* ThreadEntry(void* arg) { |
| 447 Thread* thread = reinterpret_cast<Thread*>(arg); | 423 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 448 // This is also initialized by the first argument to pthread_create() but we | 424 // This is also initialized by the first argument to pthread_create() but we |
| 449 // don't know which thread will run first (the original thread or the new | 425 // don't know which thread will run first (the original thread or the new |
| 450 // one) so we initialize it here too. | 426 // one) so we initialize it here too. |
| 451 thread_->data_->thread_ = pthread_self(); | 427 thread->data()->thread_ = pthread_self(); |
| 452 ASSERT(thread->IsValid()); | 428 ASSERT(thread->data()->thread_ != kNoThread); |
| 453 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | 429 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
| 454 thread->Run(); | 430 thread->Run(); |
| 455 return NULL; | 431 return NULL; |
| 456 } | 432 } |
| 457 | 433 |
| 458 | 434 |
| 459 void Thread::set_name(const char* name) { | 435 void Thread::set_name(const char* name) { |
| 460 strncpy(name_, name, sizeof(name_)); | 436 strncpy(name_, name, sizeof(name_)); |
| 461 name_[sizeof(name_) - 1] = '\0'; | 437 name_[sizeof(name_) - 1] = '\0'; |
| 462 } | 438 } |
| 463 | 439 |
| 464 | 440 |
| 465 void Thread::Start() { | 441 void Thread::Start() { |
| 466 pthread_attr_t* attr_ptr = NULL; | 442 pthread_attr_t* attr_ptr = NULL; |
| 467 pthread_attr_t attr; | 443 pthread_attr_t attr; |
| 468 if (stack_size_ > 0) { | 444 if (stack_size_ > 0) { |
| 469 pthread_attr_init(&attr); | 445 pthread_attr_init(&attr); |
| 470 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 446 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
| 471 attr_ptr = &attr; | 447 attr_ptr = &attr; |
| 472 } | 448 } |
| 473 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); | 449 pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this); |
| 474 ASSERT(IsValid()); | 450 ASSERT(data_->thread_ != kNoThread); |
| 475 } | 451 } |
| 476 | 452 |
| 477 | 453 |
| 478 void Thread::Join() { | 454 void Thread::Join() { |
| 479 pthread_join(thread_handle_data()->thread_, NULL); | 455 pthread_join(data_->thread_, NULL); |
| 480 } | 456 } |
| 481 | 457 |
| 482 | 458 |
| 483 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 459 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { |
| 484 pthread_key_t key; | 460 pthread_key_t key; |
| 485 int result = pthread_key_create(&key, NULL); | 461 int result = pthread_key_create(&key, NULL); |
| 486 USE(result); | 462 USE(result); |
| 487 ASSERT(result == 0); | 463 ASSERT(result == 0); |
| 488 return static_cast<LocalStorageKey>(key); | 464 return static_cast<LocalStorageKey>(key); |
| 489 } | 465 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 817 |
| 842 void Sampler::Stop() { | 818 void Sampler::Stop() { |
| 843 ASSERT(IsActive()); | 819 ASSERT(IsActive()); |
| 844 SignalSender::RemoveActiveSampler(this); | 820 SignalSender::RemoveActiveSampler(this); |
| 845 SetActive(false); | 821 SetActive(false); |
| 846 } | 822 } |
| 847 | 823 |
| 848 #endif // ENABLE_LOGGING_AND_PROFILING | 824 #endif // ENABLE_LOGGING_AND_PROFILING |
| 849 | 825 |
| 850 } } // namespace v8::internal | 826 } } // namespace v8::internal |
| OLD | NEW |