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

Unified Diff: runtime/platform/thread_win.h

Issue 9424050: Reimplement Windows Monitors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Avoid copying by holding internal lock during SetEvent Created 8 years, 10 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
« no previous file with comments | « no previous file | runtime/platform/thread_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/thread_win.h
diff --git a/runtime/platform/thread_win.h b/runtime/platform/thread_win.h
index 02165df2fa7c2c04a0238762d055df97b6a170a9..b481cec0f63dc5b11967e197763d9ac186559ac9 100644
--- a/runtime/platform/thread_win.h
+++ b/runtime/platform/thread_win.h
@@ -48,29 +48,53 @@ class MutexData {
};
+class MonitorWaitData {
+ private:
+ explicit MonitorWaitData(HANDLE event) : event_(event), next_(NULL) {}
+
+ // ThreadLocalKey used to fetch and store the MonitorWaitData object
+ // for a given thread.
+ static ThreadLocalKey monitor_wait_data_key_;
+
+ // Auto-reset event used for waiting.
+ HANDLE event_;
+ // Link to next element in the singly-linked list of waiters.
+ MonitorWaitData* next_;
+
+ friend class Monitor;
+ friend class MonitorData;
+
+ DISALLOW_COPY_AND_ASSIGN(MonitorWaitData);
+};
+
+
class MonitorData {
private:
MonitorData() {}
~MonitorData() {}
+ // Helper methods to manipulate the list of waiters for this
+ // monitor.
+ void AddWaiter(MonitorWaitData* wait_data);
+ void RemoveWaiter(MonitorWaitData* wait_data);
+ void SignalAndRemoveFirstWaiter();
+ void SignalAndRemoveAllWaiters();
+ MonitorWaitData* GetMonitorWaitDataForThread();
+
+ // The external critical section for the monitor.
CRITICAL_SECTION cs_;
// Condition variables are only available since Windows Vista. To
// support at least Windows XP, we implement our own condition
// variables using SetEvent on Event objects.
- // The notify_event_ is an auto-reset event which means that
- // SetEvent only wakes up one waiter.
- HANDLE notify_event_;
-
- // The notify_all_event_ is a manual-reset event which means that
- // SetEvent wakes up all waiters.
- HANDLE notify_all_event_;
-
- // Counter with protection used to determine the right time to reset
- // the notify_all_event_.
+ // Singly-linked list of event objects, one for each thread waiting
+ // on this monitor. New waiters are added at the end of the list.
+ // Notify signals the first element of the list (FIFO
+ // order). NotifyAll, signals all the elements of the list.
CRITICAL_SECTION waiters_cs_;
- intptr_t waiters_;
+ MonitorWaitData* waiters_head_;
+ MonitorWaitData* waiters_tail_;
friend class Monitor;
« no previous file with comments | « no previous file | runtime/platform/thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698