Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1027)

Unified Diff: runtime/vm/os_thread_win.cc

Issue 1426743002: Add lock owner information for class Monitor and add assertions for wait/notify/notifyall. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/vm/os_thread_macos.cc ('K') | « runtime/vm/os_thread_macos.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_thread_win.cc
diff --git a/runtime/vm/os_thread_win.cc b/runtime/vm/os_thread_win.cc
index d2ae84c0c5c67ea87d69a8584cc50849f5016f44..b3347c72f6b5f681b88d2aa8c9a0157e5f0f1903 100644
--- a/runtime/vm/os_thread_win.cc
+++ b/runtime/vm/os_thread_win.cc
@@ -198,8 +198,8 @@ Mutex::Mutex() {
if (data_.semaphore_ == NULL) {
FATAL1("Mutex allocation failed %d", GetLastError());
}
- // When running with assertions enabled we do track the owner.
#if defined(DEBUG)
+ // When running with assertions enabled we do track the owner.
owner_ = OSThread::kInvalidThreadId;
#endif // defined(DEBUG)
}
@@ -207,8 +207,8 @@ Mutex::Mutex() {
Mutex::~Mutex() {
CloseHandle(data_.semaphore_);
- // When running with assertions enabled we do track the owner.
#if defined(DEBUG)
+ // When running with assertions enabled we do track the owner.
ASSERT(owner_ == OSThread::kInvalidThreadId);
#endif // defined(DEBUG)
}
@@ -219,8 +219,8 @@ void Mutex::Lock() {
if (result != WAIT_OBJECT_0) {
FATAL1("Mutex lock failed %d", GetLastError());
}
- // When running with assertions enabled we do track the owner.
#if defined(DEBUG)
+ // When running with assertions enabled we do track the owner.
owner_ = OSThread::GetCurrentThreadId();
#endif // defined(DEBUG)
}
@@ -230,8 +230,8 @@ bool Mutex::TryLock() {
// Attempt to pass the semaphore but return immediately.
DWORD result = WaitForSingleObject(data_.semaphore_, 0);
if (result == WAIT_OBJECT_0) {
- // When running with assertions enabled we do track the owner.
#if defined(DEBUG)
+ // When running with assertions enabled we do track the owner.
owner_ = OSThread::GetCurrentThreadId();
#endif // defined(DEBUG)
return true;
@@ -245,8 +245,8 @@ bool Mutex::TryLock() {
void Mutex::Unlock() {
- // When running with assertions enabled we do track the owner.
#if defined(DEBUG)
+ // When running with assertions enabled we do track the owner.
ASSERT(IsOwnedByCurrentThread());
owner_ = OSThread::kInvalidThreadId;
#endif // defined(DEBUG)
@@ -266,10 +266,20 @@ Monitor::Monitor() {
InitializeCriticalSection(&data_.waiters_cs_);
data_.waiters_head_ = NULL;
data_.waiters_tail_ = NULL;
+
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ owner_ = OSThread::kInvalidThreadId;
+#endif // defined(DEBUG)
}
Monitor::~Monitor() {
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(owner_ == OSThread::kInvalidThreadId);
+#endif // defined(DEBUG)
+
DeleteCriticalSection(&data_.cs_);
DeleteCriticalSection(&data_.waiters_cs_);
}
@@ -277,10 +287,22 @@ Monitor::~Monitor() {
void Monitor::Enter() {
EnterCriticalSection(&data_.cs_);
+
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(owner_ == OSThread::kInvalidThreadId);
+ owner_ = OSThread::GetCurrentThreadId();
+#endif // defined(DEBUG)
}
void Monitor::Exit() {
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(IsOwnedByCurrentThread());
+ owner_ = OSThread::kInvalidThreadId;
+#endif // defined(DEBUG)
+
LeaveCriticalSection(&data_.cs_);
}
@@ -417,6 +439,12 @@ MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() {
Monitor::WaitResult Monitor::Wait(int64_t millis) {
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(IsOwnedByCurrentThread());
+ owner_ = OSThread::kInvalidThreadId;
+#endif // defined(DEBUG)
+
Monitor::WaitResult retval = kNotified;
// Get the wait data object containing the event to wait for.
@@ -454,6 +482,11 @@ Monitor::WaitResult Monitor::Wait(int64_t millis) {
// Reacquire the monitor critical section before continuing.
EnterCriticalSection(&data_.cs_);
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(owner_ == OSThread::kInvalidThreadId);
+ owner_ = OSThread::GetCurrentThreadId();
srdjan 2015/10/26 23:02:11 ditto
siva 2015/10/27 00:14:57 Done.
+#endif // defined(DEBUG)
return retval;
}
@@ -472,11 +505,21 @@ Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
void Monitor::Notify() {
+#if defined(DEBUG)
+ // When running with assertions enabled we track the owner.
+ ASSERT(IsOwnedByCurrentThread());
Cutch 2015/10/26 23:00:50 #if defined(DEBUG) is redundant with ASSERT.
siva 2015/10/27 00:14:57 Done.
+#endif // defined(DEBUG)
+
data_.SignalAndRemoveFirstWaiter();
}
void Monitor::NotifyAll() {
+#if defined(DEBUG)
Cutch 2015/10/26 23:00:50 #if defined(DEBUG) is redundant with ASSERT.
siva 2015/10/27 00:14:57 Done.
+ // When running with assertions enabled we track the owner.
+ ASSERT(IsOwnedByCurrentThread());
+#endif // defined(DEBUG)
+
// If one of the objects in the list of waiters wakes because of a
// timeout before we signal it, that object will get an extra
// signal. This will be treated as a spurious wake-up and is OK
« runtime/vm/os_thread_macos.cc ('K') | « runtime/vm/os_thread_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698