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 #ifndef PLATFORM_THREAD_WIN_H_ | 5 #ifndef PLATFORM_THREAD_WIN_H_ |
6 #define PLATFORM_THREAD_WIN_H_ | 6 #define PLATFORM_THREAD_WIN_H_ |
7 | 7 |
8 #if !defined(PLATFORM_THREAD_H_) | 8 #if !defined(PLATFORM_THREAD_H_) |
9 #error Do not include thread_win.h directly; use thread.h instead. | 9 #error Do not include thread_win.h directly; use thread.h instead. |
10 #endif | 10 #endif |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 HANDLE semaphore_; | 42 HANDLE semaphore_; |
43 | 43 |
44 friend class Mutex; | 44 friend class Mutex; |
45 | 45 |
46 DISALLOW_ALLOCATION(); | 46 DISALLOW_ALLOCATION(); |
47 DISALLOW_COPY_AND_ASSIGN(MutexData); | 47 DISALLOW_COPY_AND_ASSIGN(MutexData); |
48 }; | 48 }; |
49 | 49 |
50 | 50 |
| 51 class MonitorWaitData { |
| 52 private: |
| 53 explicit MonitorWaitData(HANDLE event) : event_(event), next_(NULL) {} |
| 54 |
| 55 // ThreadLocalKey used to fetch and store the MonitorWaitData object |
| 56 // for a given thread. |
| 57 static ThreadLocalKey monitor_wait_data_key_; |
| 58 |
| 59 // Auto-reset event used for waiting. |
| 60 HANDLE event_; |
| 61 // Link to next element in the singly-linked list of waiters. |
| 62 MonitorWaitData* next_; |
| 63 |
| 64 friend class Monitor; |
| 65 friend class MonitorData; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(MonitorWaitData); |
| 68 }; |
| 69 |
| 70 |
51 class MonitorData { | 71 class MonitorData { |
52 private: | 72 private: |
53 MonitorData() {} | 73 MonitorData() {} |
54 ~MonitorData() {} | 74 ~MonitorData() {} |
55 | 75 |
| 76 // Helper methods to manipulate the list of waiters for this |
| 77 // monitor. |
| 78 void AddWaiter(MonitorWaitData* wait_data); |
| 79 void RemoveWaiter(MonitorWaitData* wait_data); |
| 80 void SignalAndRemoveFirstWaiter(); |
| 81 void SignalAndRemoveAllWaiters(); |
| 82 MonitorWaitData* GetMonitorWaitDataForThread(); |
| 83 |
| 84 // The external critical section for the monitor. |
56 CRITICAL_SECTION cs_; | 85 CRITICAL_SECTION cs_; |
57 | 86 |
58 // Condition variables are only available since Windows Vista. To | 87 // Condition variables are only available since Windows Vista. To |
59 // support at least Windows XP, we implement our own condition | 88 // support at least Windows XP, we implement our own condition |
60 // variables using SetEvent on Event objects. | 89 // variables using SetEvent on Event objects. |
61 | 90 |
62 // The notify_event_ is an auto-reset event which means that | 91 // Singly-linked list of event objects, one for each thread waiting |
63 // SetEvent only wakes up one waiter. | 92 // on this monitor. New waiters are added at the end of the list. |
64 HANDLE notify_event_; | 93 // Notify signals the first element of the list (FIFO |
65 | 94 // order). NotifyAll, signals all the elements of the list. |
66 // The notify_all_event_ is a manual-reset event which means that | |
67 // SetEvent wakes up all waiters. | |
68 HANDLE notify_all_event_; | |
69 | |
70 // Counter with protection used to determine the right time to reset | |
71 // the notify_all_event_. | |
72 CRITICAL_SECTION waiters_cs_; | 95 CRITICAL_SECTION waiters_cs_; |
73 intptr_t waiters_; | 96 MonitorWaitData* waiters_head_; |
| 97 MonitorWaitData* waiters_tail_; |
74 | 98 |
75 friend class Monitor; | 99 friend class Monitor; |
76 | 100 |
77 DISALLOW_ALLOCATION(); | 101 DISALLOW_ALLOCATION(); |
78 DISALLOW_COPY_AND_ASSIGN(MonitorData); | 102 DISALLOW_COPY_AND_ASSIGN(MonitorData); |
79 }; | 103 }; |
80 | 104 |
81 } // namespace dart | 105 } // namespace dart |
82 | 106 |
83 #endif // PLATFORM_THREAD_WIN_H_ | 107 #endif // PLATFORM_THREAD_WIN_H_ |
OLD | NEW |