| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" | 
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) | 
| 7 | 7 | 
| 8 #include "vm/thread.h" | 8 #include "vm/thread.h" | 
| 9 | 9 | 
| 10 #include <process.h>  // NOLINT | 10 #include <process.h>  // NOLINT | 
| 11 | 11 | 
| 12 #include "platform/assert.h" | 12 #include "platform/assert.h" | 
|  | 13 #include "vm/isolate.h" | 
| 13 | 14 | 
| 14 namespace dart { | 15 namespace dart { | 
| 15 | 16 | 
| 16 class ThreadStartData { | 17 class ThreadStartData { | 
| 17  public: | 18  public: | 
| 18   ThreadStartData(Thread::ThreadStartFunction function, uword parameter) | 19   ThreadStartData(Thread::ThreadStartFunction function, uword parameter) | 
| 19       : function_(function), parameter_(parameter) {} | 20       : function_(function), parameter_(parameter) {} | 
| 20 | 21 | 
| 21   Thread::ThreadStartFunction function() const { return function_; } | 22   Thread::ThreadStartFunction function() const { return function_; } | 
| 22   uword parameter() const { return parameter_; } | 23   uword parameter() const { return parameter_; } | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 163   } | 164   } | 
| 164 } | 165 } | 
| 165 | 166 | 
| 166 | 167 | 
| 167 Mutex::Mutex() { | 168 Mutex::Mutex() { | 
| 168   // Allocate unnamed semaphore with initial count 1 and max count 1. | 169   // Allocate unnamed semaphore with initial count 1 and max count 1. | 
| 169   data_.semaphore_ = CreateSemaphore(NULL, 1, 1, NULL); | 170   data_.semaphore_ = CreateSemaphore(NULL, 1, 1, NULL); | 
| 170   if (data_.semaphore_ == NULL) { | 171   if (data_.semaphore_ == NULL) { | 
| 171     FATAL1("Mutex allocation failed %d", GetLastError()); | 172     FATAL1("Mutex allocation failed %d", GetLastError()); | 
| 172   } | 173   } | 
|  | 174   // When running with assertions enabled we do track the owner. | 
|  | 175 #if defined(DEBUG) | 
|  | 176   owner_ = NULL; | 
|  | 177 #endif  // defined(DEBUG) | 
| 173 } | 178 } | 
| 174 | 179 | 
| 175 | 180 | 
| 176 Mutex::~Mutex() { | 181 Mutex::~Mutex() { | 
| 177   CloseHandle(data_.semaphore_); | 182   CloseHandle(data_.semaphore_); | 
|  | 183   // When running with assertions enabled we do track the owner. | 
|  | 184 #if defined(DEBUG) | 
|  | 185   ASSERT(owner_ == NULL); | 
|  | 186 #endif  // defined(DEBUG) | 
| 178 } | 187 } | 
| 179 | 188 | 
| 180 | 189 | 
| 181 void Mutex::Lock() { | 190 void Mutex::Lock() { | 
| 182   DWORD result = WaitForSingleObject(data_.semaphore_, INFINITE); | 191   DWORD result = WaitForSingleObject(data_.semaphore_, INFINITE); | 
| 183   if (result != WAIT_OBJECT_0) { | 192   if (result != WAIT_OBJECT_0) { | 
| 184     FATAL1("Mutex lock failed %d", GetLastError()); | 193     FATAL1("Mutex lock failed %d", GetLastError()); | 
| 185   } | 194   } | 
|  | 195   // When running with assertions enabled we do track the owner. | 
|  | 196 #if defined(DEBUG) | 
|  | 197   owner_ = Isolate::Current(); | 
|  | 198 #endif  // defined(DEBUG) | 
| 186 } | 199 } | 
| 187 | 200 | 
| 188 | 201 | 
| 189 bool Mutex::TryLock() { | 202 bool Mutex::TryLock() { | 
| 190   // Attempt to pass the semaphore but return immediately. | 203   // Attempt to pass the semaphore but return immediately. | 
| 191   DWORD result = WaitForSingleObject(data_.semaphore_, 0); | 204   DWORD result = WaitForSingleObject(data_.semaphore_, 0); | 
| 192   if (result == WAIT_OBJECT_0) { | 205   if (result == WAIT_OBJECT_0) { | 
|  | 206     // When running with assertions enabled we do track the owner. | 
|  | 207 #if defined(DEBUG) | 
|  | 208     owner_ = Isolate::Current(); | 
|  | 209 #endif  // defined(DEBUG) | 
| 193     return true; | 210     return true; | 
| 194   } | 211   } | 
| 195   if (result == WAIT_ABANDONED || result == WAIT_FAILED) { | 212   if (result == WAIT_ABANDONED || result == WAIT_FAILED) { | 
| 196     FATAL1("Mutex try lock failed %d", GetLastError()); | 213     FATAL1("Mutex try lock failed %d", GetLastError()); | 
| 197   } | 214   } | 
| 198   ASSERT(result == WAIT_TIMEOUT); | 215   ASSERT(result == WAIT_TIMEOUT); | 
| 199   return false; | 216   return false; | 
| 200 } | 217 } | 
| 201 | 218 | 
| 202 | 219 | 
| 203 void Mutex::Unlock() { | 220 void Mutex::Unlock() { | 
|  | 221   // When running with assertions enabled we do track the owner. | 
|  | 222 #if defined(DEBUG) | 
|  | 223   ASSERT(owner_ == Isolate::Current()); | 
|  | 224   owner_ = NULL; | 
|  | 225 #endif  // defined(DEBUG) | 
| 204   BOOL result = ReleaseSemaphore(data_.semaphore_, 1, NULL); | 226   BOOL result = ReleaseSemaphore(data_.semaphore_, 1, NULL); | 
| 205   if (result == 0) { | 227   if (result == 0) { | 
| 206     FATAL1("Mutex unlock failed %d", GetLastError()); | 228     FATAL1("Mutex unlock failed %d", GetLastError()); | 
| 207   } | 229   } | 
| 208 } | 230 } | 
| 209 | 231 | 
| 210 | 232 | 
| 211 ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = | 233 ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = | 
| 212     Thread::kUnsetThreadLocalKey; | 234     Thread::kUnsetThreadLocalKey; | 
| 213 | 235 | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 430   // timeout before we signal it, that object will get an extra | 452   // timeout before we signal it, that object will get an extra | 
| 431   // signal. This will be treated as a spurious wake-up and is OK | 453   // signal. This will be treated as a spurious wake-up and is OK | 
| 432   // since all uses of monitors should recheck the condition after a | 454   // since all uses of monitors should recheck the condition after a | 
| 433   // Wait. | 455   // Wait. | 
| 434   data_.SignalAndRemoveAllWaiters(); | 456   data_.SignalAndRemoveAllWaiters(); | 
| 435 } | 457 } | 
| 436 | 458 | 
| 437 }  // namespace dart | 459 }  // namespace dart | 
| 438 | 460 | 
| 439 #endif  // defined(TARGET_OS_WINDOWS) | 461 #endif  // defined(TARGET_OS_WINDOWS) | 
| OLD | NEW | 
|---|