| Index: runtime/vm/os_thread_win.cc
|
| diff --git a/runtime/vm/os_thread_win.cc b/runtime/vm/os_thread_win.cc
|
| index 1c158352135d76d5cc4b6c6769a1cc5ead9500e4..dcd44eabe77dfedf47ee9562d7cf4fe489f2f063 100644
|
| --- a/runtime/vm/os_thread_win.cc
|
| +++ b/runtime/vm/os_thread_win.cc
|
| @@ -38,7 +38,6 @@ class ThreadStartData {
|
| DISALLOW_COPY_AND_ASSIGN(ThreadStartData);
|
| };
|
|
|
| -
|
| // Dispatch to the thread start function provided by the caller. This trampoline
|
| // is used to ensure that the thread is properly destroyed if the thread just
|
| // exits.
|
| @@ -68,7 +67,6 @@ static unsigned int __stdcall ThreadEntry(void* data_ptr) {
|
| return 0;
|
| }
|
|
|
| -
|
| int OSThread::Start(const char* name,
|
| ThreadStartFunction function,
|
| uword parameter) {
|
| @@ -89,11 +87,9 @@ int OSThread::Start(const char* name,
|
| return 0;
|
| }
|
|
|
| -
|
| const ThreadId OSThread::kInvalidThreadId = 0;
|
| const ThreadJoinId OSThread::kInvalidThreadJoinId = NULL;
|
|
|
| -
|
| ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) {
|
| ThreadLocalKey key = TlsAlloc();
|
| if (key == kUnsetThreadLocalKey) {
|
| @@ -103,7 +99,6 @@ ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) {
|
| return key;
|
| }
|
|
|
| -
|
| void OSThread::DeleteThreadLocal(ThreadLocalKey key) {
|
| ASSERT(key != kUnsetThreadLocalKey);
|
| BOOL result = TlsFree(key);
|
| @@ -113,25 +108,21 @@ void OSThread::DeleteThreadLocal(ThreadLocalKey key) {
|
| ThreadLocalData::RemoveThreadLocal(key);
|
| }
|
|
|
| -
|
| intptr_t OSThread::GetMaxStackSize() {
|
| const int kStackSize = (128 * kWordSize * KB);
|
| return kStackSize;
|
| }
|
|
|
| -
|
| ThreadId OSThread::GetCurrentThreadId() {
|
| return ::GetCurrentThreadId();
|
| }
|
|
|
| -
|
| #ifndef PRODUCT
|
| ThreadId OSThread::GetCurrentThreadTraceId() {
|
| return ::GetCurrentThreadId();
|
| }
|
| #endif // PRODUCT
|
|
|
| -
|
| ThreadJoinId OSThread::GetCurrentThreadJoinId(OSThread* thread) {
|
| ASSERT(thread != NULL);
|
| // Make sure we're filling in the join id for the current thread.
|
| @@ -147,7 +138,6 @@ ThreadJoinId OSThread::GetCurrentThreadJoinId(OSThread* thread) {
|
| return handle;
|
| }
|
|
|
| -
|
| void OSThread::Join(ThreadJoinId id) {
|
| HANDLE handle = static_cast<HANDLE>(id);
|
| ASSERT(handle != NULL);
|
| @@ -156,23 +146,19 @@ void OSThread::Join(ThreadJoinId id) {
|
| ASSERT(res == WAIT_OBJECT_0);
|
| }
|
|
|
| -
|
| intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) {
|
| ASSERT(sizeof(id) <= sizeof(intptr_t));
|
| return static_cast<intptr_t>(id);
|
| }
|
|
|
| -
|
| ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) {
|
| return static_cast<ThreadId>(id);
|
| }
|
|
|
| -
|
| bool OSThread::Compare(ThreadId a, ThreadId b) {
|
| return a == b;
|
| }
|
|
|
| -
|
| bool OSThread::GetCurrentStackBounds(uword* lower, uword* upper) {
|
| // On Windows stack limits for the current thread are available in
|
| // the thread information block (TIB). Its fields can be accessed through
|
| @@ -187,7 +173,6 @@ bool OSThread::GetCurrentStackBounds(uword* lower, uword* upper) {
|
| return true;
|
| }
|
|
|
| -
|
| void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) {
|
| ASSERT(key != kUnsetThreadLocalKey);
|
| BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value));
|
| @@ -196,7 +181,6 @@ void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) {
|
| }
|
| }
|
|
|
| -
|
| Mutex::Mutex() {
|
| // Allocate unnamed semaphore with initial count 1 and max count 1.
|
| data_.semaphore_ = CreateSemaphore(NULL, 1, 1, NULL);
|
| @@ -209,7 +193,6 @@ Mutex::Mutex() {
|
| #endif // defined(DEBUG)
|
| }
|
|
|
| -
|
| Mutex::~Mutex() {
|
| CloseHandle(data_.semaphore_);
|
| #if defined(DEBUG)
|
| @@ -218,7 +201,6 @@ Mutex::~Mutex() {
|
| #endif // defined(DEBUG)
|
| }
|
|
|
| -
|
| void Mutex::Lock() {
|
| DWORD result = WaitForSingleObject(data_.semaphore_, INFINITE);
|
| if (result != WAIT_OBJECT_0) {
|
| @@ -230,7 +212,6 @@ void Mutex::Lock() {
|
| #endif // defined(DEBUG)
|
| }
|
|
|
| -
|
| bool Mutex::TryLock() {
|
| // Attempt to pass the semaphore but return immediately.
|
| DWORD result = WaitForSingleObject(data_.semaphore_, 0);
|
| @@ -248,7 +229,6 @@ bool Mutex::TryLock() {
|
| return false;
|
| }
|
|
|
| -
|
| void Mutex::Unlock() {
|
| #if defined(DEBUG)
|
| // When running with assertions enabled we do track the owner.
|
| @@ -261,10 +241,8 @@ void Mutex::Unlock() {
|
| }
|
| }
|
|
|
| -
|
| ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = kUnsetThreadLocalKey;
|
|
|
| -
|
| Monitor::Monitor() {
|
| InitializeCriticalSection(&data_.cs_);
|
| InitializeCriticalSection(&data_.waiters_cs_);
|
| @@ -277,7 +255,6 @@ Monitor::Monitor() {
|
| #endif // defined(DEBUG)
|
| }
|
|
|
| -
|
| Monitor::~Monitor() {
|
| #if defined(DEBUG)
|
| // When running with assertions enabled we track the owner.
|
| @@ -288,7 +265,6 @@ Monitor::~Monitor() {
|
| DeleteCriticalSection(&data_.waiters_cs_);
|
| }
|
|
|
| -
|
| bool Monitor::TryEnter() {
|
| // Attempt to pass the semaphore but return immediately.
|
| BOOL result = TryEnterCriticalSection(&data_.cs_);
|
| @@ -303,7 +279,6 @@ bool Monitor::TryEnter() {
|
| return true;
|
| }
|
|
|
| -
|
| void Monitor::Enter() {
|
| EnterCriticalSection(&data_.cs_);
|
|
|
| @@ -314,7 +289,6 @@ void Monitor::Enter() {
|
| #endif // defined(DEBUG)
|
| }
|
|
|
| -
|
| void Monitor::Exit() {
|
| #if defined(DEBUG)
|
| // When running with assertions enabled we track the owner.
|
| @@ -325,7 +299,6 @@ void Monitor::Exit() {
|
| LeaveCriticalSection(&data_.cs_);
|
| }
|
|
|
| -
|
| void MonitorWaitData::ThreadExit() {
|
| if (MonitorWaitData::monitor_wait_data_key_ != kUnsetThreadLocalKey) {
|
| uword raw_wait_data =
|
| @@ -340,7 +313,6 @@ void MonitorWaitData::ThreadExit() {
|
| }
|
| }
|
|
|
| -
|
| void MonitorData::AddWaiter(MonitorWaitData* wait_data) {
|
| // Add the MonitorWaitData object to the list of objects waiting for
|
| // this monitor.
|
| @@ -355,7 +327,6 @@ void MonitorData::AddWaiter(MonitorWaitData* wait_data) {
|
| LeaveCriticalSection(&waiters_cs_);
|
| }
|
|
|
| -
|
| void MonitorData::RemoveWaiter(MonitorWaitData* wait_data) {
|
| // Remove the MonitorWaitData object from the list of objects
|
| // waiting for this monitor.
|
| @@ -386,7 +357,6 @@ void MonitorData::RemoveWaiter(MonitorWaitData* wait_data) {
|
| LeaveCriticalSection(&waiters_cs_);
|
| }
|
|
|
| -
|
| void MonitorData::SignalAndRemoveFirstWaiter() {
|
| EnterCriticalSection(&waiters_cs_);
|
| MonitorWaitData* first = waiters_head_;
|
| @@ -408,7 +378,6 @@ void MonitorData::SignalAndRemoveFirstWaiter() {
|
| LeaveCriticalSection(&waiters_cs_);
|
| }
|
|
|
| -
|
| void MonitorData::SignalAndRemoveAllWaiters() {
|
| EnterCriticalSection(&waiters_cs_);
|
| // Extract list to signal.
|
| @@ -431,7 +400,6 @@ void MonitorData::SignalAndRemoveAllWaiters() {
|
| LeaveCriticalSection(&waiters_cs_);
|
| }
|
|
|
| -
|
| MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() {
|
| // Ensure that the thread local key for monitor wait data objects is
|
| // initialized.
|
| @@ -454,7 +422,6 @@ MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() {
|
| return wait_data;
|
| }
|
|
|
| -
|
| Monitor::WaitResult Monitor::Wait(int64_t millis) {
|
| #if defined(DEBUG)
|
| // When running with assertions enabled we track the owner.
|
| @@ -509,7 +476,6 @@ Monitor::WaitResult Monitor::Wait(int64_t millis) {
|
| return retval;
|
| }
|
|
|
| -
|
| Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
|
| // TODO(johnmccutchan): Investigate sub-millisecond sleep times on Windows.
|
| int64_t millis = micros / kMicrosecondsPerMillisecond;
|
| @@ -522,14 +488,12 @@ Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
|
| return Wait(millis);
|
| }
|
|
|
| -
|
| void Monitor::Notify() {
|
| // When running with assertions enabled we track the owner.
|
| ASSERT(IsOwnedByCurrentThread());
|
| data_.SignalAndRemoveFirstWaiter();
|
| }
|
|
|
| -
|
| void Monitor::NotifyAll() {
|
| // When running with assertions enabled we track the owner.
|
| ASSERT(IsOwnedByCurrentThread());
|
| @@ -541,7 +505,6 @@ void Monitor::NotifyAll() {
|
| data_.SignalAndRemoveAllWaiters();
|
| }
|
|
|
| -
|
| void ThreadLocalData::AddThreadLocal(ThreadLocalKey key,
|
| ThreadDestructor destructor) {
|
| ASSERT(thread_locals_ != NULL);
|
| @@ -561,7 +524,6 @@ void ThreadLocalData::AddThreadLocal(ThreadLocalKey key,
|
| thread_locals_->Add(ThreadLocalEntry(key, destructor));
|
| }
|
|
|
| -
|
| void ThreadLocalData::RemoveThreadLocal(ThreadLocalKey key) {
|
| ASSERT(thread_locals_ != NULL);
|
| MutexLocker ml(mutex_, false);
|
| @@ -579,7 +541,6 @@ void ThreadLocalData::RemoveThreadLocal(ThreadLocalKey key) {
|
| thread_locals_->RemoveAt(i);
|
| }
|
|
|
| -
|
| // This function is executed on the thread that is exiting. It is invoked
|
| // by |OnDartThreadExit| (see below for notes on TLS destructors on Windows).
|
| void ThreadLocalData::RunDestructors() {
|
| @@ -595,17 +556,14 @@ void ThreadLocalData::RunDestructors() {
|
| }
|
| }
|
|
|
| -
|
| Mutex* ThreadLocalData::mutex_ = NULL;
|
| MallocGrowableArray<ThreadLocalEntry>* ThreadLocalData::thread_locals_ = NULL;
|
|
|
| -
|
| void ThreadLocalData::InitOnce() {
|
| mutex_ = new Mutex();
|
| thread_locals_ = new MallocGrowableArray<ThreadLocalEntry>();
|
| }
|
|
|
| -
|
| void ThreadLocalData::Shutdown() {
|
| if (mutex_ != NULL) {
|
| delete mutex_;
|
| @@ -617,7 +575,6 @@ void ThreadLocalData::Shutdown() {
|
| }
|
| }
|
|
|
| -
|
| } // namespace dart
|
|
|
| // The following was adapted from Chromium:
|
|
|