OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #ifndef VM_THREAD_WIN_H_ | |
6 #define VM_THREAD_WIN_H_ | |
7 | |
8 #if !defined(VM_THREAD_H_) | |
9 #error Do not include thread_win.h directly; use thread.h instead. | |
10 #endif | |
11 | |
12 #include "platform/assert.h" | |
13 #include "platform/globals.h" | |
14 | |
15 namespace dart { | |
16 | |
17 typedef DWORD ThreadLocalKey; | |
18 typedef DWORD ThreadId; | |
19 | |
20 | |
21 class ThreadInlineImpl { | |
22 private: | |
23 ThreadInlineImpl() {} | |
24 ~ThreadInlineImpl() {} | |
25 | |
26 static uword GetThreadLocal(ThreadLocalKey key) { | |
27 static ThreadLocalKey kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES; | |
28 ASSERT(key != kUnsetThreadLocalKey); | |
29 return reinterpret_cast<uword>(TlsGetValue(key)); | |
30 } | |
31 | |
32 friend class Thread; | |
33 friend unsigned int __stdcall ThreadEntry(void* data_ptr); | |
34 | |
35 DISALLOW_ALLOCATION(); | |
36 DISALLOW_COPY_AND_ASSIGN(ThreadInlineImpl); | |
37 }; | |
38 | |
39 | |
40 class MutexData { | |
41 private: | |
42 MutexData() {} | |
43 ~MutexData() {} | |
44 | |
45 HANDLE semaphore_; | |
46 | |
47 friend class Mutex; | |
48 | |
49 DISALLOW_ALLOCATION(); | |
50 DISALLOW_COPY_AND_ASSIGN(MutexData); | |
51 }; | |
52 | |
53 | |
54 class MonitorWaitData { | |
55 public: | |
56 static void ThreadExit(); | |
57 | |
58 private: | |
59 explicit MonitorWaitData(HANDLE event) : event_(event), next_(NULL) {} | |
60 ~MonitorWaitData() { | |
61 CloseHandle(event_); | |
62 ASSERT(next_ == NULL); | |
63 } | |
64 | |
65 // ThreadLocalKey used to fetch and store the MonitorWaitData object | |
66 // for a given thread. | |
67 static ThreadLocalKey monitor_wait_data_key_; | |
68 | |
69 // Auto-reset event used for waiting. | |
70 HANDLE event_; | |
71 // Link to next element in the singly-linked list of waiters. | |
72 MonitorWaitData* next_; | |
73 | |
74 friend class Monitor; | |
75 friend class MonitorData; | |
76 friend class OS; | |
77 | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(MonitorWaitData); | |
80 }; | |
81 | |
82 | |
83 class MonitorData { | |
84 private: | |
85 MonitorData() {} | |
86 ~MonitorData() {} | |
87 | |
88 // Helper methods to manipulate the list of waiters for this | |
89 // monitor. | |
90 void AddWaiter(MonitorWaitData* wait_data); | |
91 void RemoveWaiter(MonitorWaitData* wait_data); | |
92 void SignalAndRemoveFirstWaiter(); | |
93 void SignalAndRemoveAllWaiters(); | |
94 static MonitorWaitData* GetMonitorWaitDataForThread(); | |
95 | |
96 // The external critical section for the monitor. | |
97 CRITICAL_SECTION cs_; | |
98 | |
99 // Condition variables are only available since Windows Vista. To | |
100 // support at least Windows XP, we implement our own condition | |
101 // variables using SetEvent on Event objects. | |
102 | |
103 // Singly-linked list of event objects, one for each thread waiting | |
104 // on this monitor. New waiters are added at the end of the list. | |
105 // Notify signals the first element of the list (FIFO | |
106 // order). NotifyAll, signals all the elements of the list. | |
107 CRITICAL_SECTION waiters_cs_; | |
108 MonitorWaitData* waiters_head_; | |
109 MonitorWaitData* waiters_tail_; | |
110 | |
111 friend class Monitor; | |
112 friend class OS; | |
113 friend unsigned int __stdcall ThreadEntry(void* data_ptr); | |
114 | |
115 DISALLOW_ALLOCATION(); | |
116 DISALLOW_COPY_AND_ASSIGN(MonitorData); | |
117 }; | |
118 | |
119 } // namespace dart | |
120 | |
121 #endif // VM_THREAD_WIN_H_ | |
OLD | NEW |