Chromium Code Reviews| 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_; | |
|
cshapiro
2012/02/21 18:49:36
This event handle should be stored in Thread there
Mads Ager (google)
2012/02/22 12:32:51
I don't understand. I allocate exactly one event p
| |
| 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 MonitorWaitData* RemoveFirstWaiter(); | |
| 81 MonitorWaitData** RemoveAllWaiters(); | |
| 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. |
|
cshapiro
2012/02/21 18:49:36
This behavior is not performance sensitive. Notif
Mads Ager (google)
2012/02/22 12:32:51
This design does sound nice. I would like to go wi
| |
| 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_; |
| 96 MonitorWaitData* waiters_head_; | |
| 97 MonitorWaitData* waiters_tail_; | |
| 73 intptr_t waiters_; | 98 intptr_t waiters_; |
| 74 | 99 |
| 75 friend class Monitor; | 100 friend class Monitor; |
| 76 | 101 |
| 77 DISALLOW_ALLOCATION(); | 102 DISALLOW_ALLOCATION(); |
| 78 DISALLOW_COPY_AND_ASSIGN(MonitorData); | 103 DISALLOW_COPY_AND_ASSIGN(MonitorData); |
| 79 }; | 104 }; |
| 80 | 105 |
| 81 } // namespace dart | 106 } // namespace dart |
| 82 | 107 |
| 83 #endif // PLATFORM_THREAD_WIN_H_ | 108 #endif // PLATFORM_THREAD_WIN_H_ |
| OLD | NEW |