OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 Thread* thread = reinterpret_cast<Thread*>(arg); | 1504 Thread* thread = reinterpret_cast<Thread*>(arg); |
1505 thread->Run(); | 1505 thread->Run(); |
1506 return 0; | 1506 return 0; |
1507 } | 1507 } |
1508 | 1508 |
1509 | 1509 |
1510 class Thread::PlatformData : public Malloced { | 1510 class Thread::PlatformData : public Malloced { |
1511 public: | 1511 public: |
1512 explicit PlatformData(HANDLE thread) : thread_(thread) {} | 1512 explicit PlatformData(HANDLE thread) : thread_(thread) {} |
1513 HANDLE thread_; | 1513 HANDLE thread_; |
| 1514 unsigned thread_id_; |
1514 }; | 1515 }; |
1515 | 1516 |
1516 | 1517 |
1517 // Initialize a Win32 thread object. The thread has an invalid thread | 1518 // Initialize a Win32 thread object. The thread has an invalid thread |
1518 // handle until it is started. | 1519 // handle until it is started. |
1519 | 1520 |
1520 Thread::Thread(const Options& options) | 1521 Thread::Thread(const Options& options) |
1521 : stack_size_(options.stack_size) { | 1522 : stack_size_(options.stack_size) { |
1522 data_ = new PlatformData(kNoThread); | 1523 data_ = new PlatformData(kNoThread); |
1523 set_name(options.name); | 1524 set_name(options.name); |
(...skipping 23 matching lines...) Expand all Loading... |
1547 // Create a new thread. It is important to use _beginthreadex() instead of | 1548 // Create a new thread. It is important to use _beginthreadex() instead of |
1548 // the Win32 function CreateThread(), because the CreateThread() does not | 1549 // the Win32 function CreateThread(), because the CreateThread() does not |
1549 // initialize thread specific structures in the C runtime library. | 1550 // initialize thread specific structures in the C runtime library. |
1550 void Thread::Start() { | 1551 void Thread::Start() { |
1551 data_->thread_ = reinterpret_cast<HANDLE>( | 1552 data_->thread_ = reinterpret_cast<HANDLE>( |
1552 _beginthreadex(NULL, | 1553 _beginthreadex(NULL, |
1553 static_cast<unsigned>(stack_size_), | 1554 static_cast<unsigned>(stack_size_), |
1554 ThreadEntry, | 1555 ThreadEntry, |
1555 this, | 1556 this, |
1556 0, | 1557 0, |
1557 NULL)); | 1558 &data_->thread_id_)); |
1558 } | 1559 } |
1559 | 1560 |
1560 | 1561 |
1561 // Wait for thread to terminate. | 1562 // Wait for thread to terminate. |
1562 void Thread::Join() { | 1563 void Thread::Join() { |
1563 WaitForSingleObject(data_->thread_, INFINITE); | 1564 if (data_->thread_id_ != GetCurrentThreadId()) { |
| 1565 WaitForSingleObject(data_->thread_, INFINITE); |
| 1566 } |
1564 } | 1567 } |
1565 | 1568 |
1566 | 1569 |
1567 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 1570 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { |
1568 DWORD result = TlsAlloc(); | 1571 DWORD result = TlsAlloc(); |
1569 ASSERT(result != TLS_OUT_OF_INDEXES); | 1572 ASSERT(result != TLS_OUT_OF_INDEXES); |
1570 return static_cast<LocalStorageKey>(result); | 1573 return static_cast<LocalStorageKey>(result); |
1571 } | 1574 } |
1572 | 1575 |
1573 | 1576 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 | 2031 |
2029 | 2032 |
2030 void Sampler::Stop() { | 2033 void Sampler::Stop() { |
2031 ASSERT(IsActive()); | 2034 ASSERT(IsActive()); |
2032 SamplerThread::RemoveActiveSampler(this); | 2035 SamplerThread::RemoveActiveSampler(this); |
2033 SetActive(false); | 2036 SetActive(false); |
2034 } | 2037 } |
2035 | 2038 |
2036 | 2039 |
2037 } } // namespace v8::internal | 2040 } } // namespace v8::internal |
OLD | NEW |