| 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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 class Thread::PlatformData : public Malloced { | 1496 class Thread::PlatformData : public Malloced { |
| 1497 public: | 1497 public: |
| 1498 explicit PlatformData(HANDLE thread) : thread_(thread) {} | 1498 explicit PlatformData(HANDLE thread) : thread_(thread) {} |
| 1499 HANDLE thread_; | 1499 HANDLE thread_; |
| 1500 }; | 1500 }; |
| 1501 | 1501 |
| 1502 | 1502 |
| 1503 // Initialize a Win32 thread object. The thread has an invalid thread | 1503 // Initialize a Win32 thread object. The thread has an invalid thread |
| 1504 // handle until it is started. | 1504 // handle until it is started. |
| 1505 | 1505 |
| 1506 Thread::Thread(Isolate* isolate) | 1506 Thread::Thread(Isolate* isolate, const Options& options) |
| 1507 : ThreadHandle(ThreadHandle::INVALID), | 1507 : ThreadHandle(ThreadHandle::INVALID), |
| 1508 isolate_(isolate) { | 1508 isolate_(isolate), |
| 1509 stack_size_(options.stack_size) { |
| 1509 data_ = new PlatformData(kNoThread); | 1510 data_ = new PlatformData(kNoThread); |
| 1510 set_name("v8:<unknown>"); | 1511 set_name(options.name); |
| 1511 } | 1512 } |
| 1512 | 1513 |
| 1513 | 1514 |
| 1514 Thread::Thread(Isolate* isolate, const char* name) | 1515 Thread::Thread(Isolate* isolate, const char* name) |
| 1515 : ThreadHandle(ThreadHandle::INVALID), | 1516 : ThreadHandle(ThreadHandle::INVALID), |
| 1516 isolate_(isolate) { | 1517 isolate_(isolate), |
| 1518 stack_size_(0) { |
| 1517 data_ = new PlatformData(kNoThread); | 1519 data_ = new PlatformData(kNoThread); |
| 1518 set_name(name); | 1520 set_name(name); |
| 1519 } | 1521 } |
| 1520 | 1522 |
| 1521 | 1523 |
| 1522 void Thread::set_name(const char* name) { | 1524 void Thread::set_name(const char* name) { |
| 1523 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); | 1525 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); |
| 1524 name_[sizeof(name_) - 1] = '\0'; | 1526 name_[sizeof(name_) - 1] = '\0'; |
| 1525 } | 1527 } |
| 1526 | 1528 |
| 1527 | 1529 |
| 1528 // Close our own handle for the thread. | 1530 // Close our own handle for the thread. |
| 1529 Thread::~Thread() { | 1531 Thread::~Thread() { |
| 1530 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_); | 1532 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_); |
| 1531 delete data_; | 1533 delete data_; |
| 1532 } | 1534 } |
| 1533 | 1535 |
| 1534 | 1536 |
| 1535 // Create a new thread. It is important to use _beginthreadex() instead of | 1537 // Create a new thread. It is important to use _beginthreadex() instead of |
| 1536 // the Win32 function CreateThread(), because the CreateThread() does not | 1538 // the Win32 function CreateThread(), because the CreateThread() does not |
| 1537 // initialize thread specific structures in the C runtime library. | 1539 // initialize thread specific structures in the C runtime library. |
| 1538 void Thread::Start() { | 1540 void Thread::Start() { |
| 1539 data_->thread_ = reinterpret_cast<HANDLE>( | 1541 data_->thread_ = reinterpret_cast<HANDLE>( |
| 1540 _beginthreadex(NULL, | 1542 _beginthreadex(NULL, |
| 1541 0, | 1543 static_cast<unsigned>(stack_size_), |
| 1542 ThreadEntry, | 1544 ThreadEntry, |
| 1543 this, | 1545 this, |
| 1544 0, | 1546 0, |
| 1545 reinterpret_cast<unsigned int*>( | 1547 reinterpret_cast<unsigned int*>( |
| 1546 &thread_handle_data()->tid_))); | 1548 &thread_handle_data()->tid_))); |
| 1547 ASSERT(IsValid()); | 1549 ASSERT(IsValid()); |
| 1548 } | 1550 } |
| 1549 | 1551 |
| 1550 | 1552 |
| 1551 // Wait for thread to terminate. | 1553 // Wait for thread to terminate. |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 | 1879 |
| 1878 HANDLE profiled_thread() { return profiled_thread_; } | 1880 HANDLE profiled_thread() { return profiled_thread_; } |
| 1879 | 1881 |
| 1880 private: | 1882 private: |
| 1881 HANDLE profiled_thread_; | 1883 HANDLE profiled_thread_; |
| 1882 }; | 1884 }; |
| 1883 | 1885 |
| 1884 | 1886 |
| 1885 class SamplerThread : public Thread { | 1887 class SamplerThread : public Thread { |
| 1886 public: | 1888 public: |
| 1887 explicit SamplerThread(int interval) : Thread(NULL), interval_(interval) {} | 1889 explicit SamplerThread(int interval) |
| 1890 : Thread(NULL, "SamplerThread"), |
| 1891 interval_(interval) {} |
| 1888 | 1892 |
| 1889 static void AddActiveSampler(Sampler* sampler) { | 1893 static void AddActiveSampler(Sampler* sampler) { |
| 1890 ScopedLock lock(mutex_); | 1894 ScopedLock lock(mutex_); |
| 1891 SamplerRegistry::AddActiveSampler(sampler); | 1895 SamplerRegistry::AddActiveSampler(sampler); |
| 1892 if (instance_ == NULL) { | 1896 if (instance_ == NULL) { |
| 1893 instance_ = new SamplerThread(sampler->interval()); | 1897 instance_ = new SamplerThread(sampler->interval()); |
| 1894 instance_->Start(); | 1898 instance_->Start(); |
| 1895 } else { | 1899 } else { |
| 1896 ASSERT(instance_->interval_ == sampler->interval()); | 1900 ASSERT(instance_->interval_ == sampler->interval()); |
| 1897 } | 1901 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 | 2024 |
| 2021 void Sampler::Stop() { | 2025 void Sampler::Stop() { |
| 2022 ASSERT(IsActive()); | 2026 ASSERT(IsActive()); |
| 2023 SamplerThread::RemoveActiveSampler(this); | 2027 SamplerThread::RemoveActiveSampler(this); |
| 2024 SetActive(false); | 2028 SetActive(false); |
| 2025 } | 2029 } |
| 2026 | 2030 |
| 2027 #endif // ENABLE_LOGGING_AND_PROFILING | 2031 #endif // ENABLE_LOGGING_AND_PROFILING |
| 2028 | 2032 |
| 2029 } } // namespace v8::internal | 2033 } } // namespace v8::internal |
| OLD | NEW |