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 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
(...skipping 24 matching lines...) Expand all Loading... |
35 static unsigned int __stdcall ThreadEntry(void* data_ptr) { | 35 static unsigned int __stdcall ThreadEntry(void* data_ptr) { |
36 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); | 36 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); |
37 | 37 |
38 Thread::ThreadStartFunction function = data->function(); | 38 Thread::ThreadStartFunction function = data->function(); |
39 uword parameter = data->parameter(); | 39 uword parameter = data->parameter(); |
40 delete data; | 40 delete data; |
41 | 41 |
42 // Call the supplied thread start function handing it its parameters. | 42 // Call the supplied thread start function handing it its parameters. |
43 function(parameter); | 43 function(parameter); |
44 | 44 |
45 // When the function returns here close the handle. | 45 // Clean up the monitor wait data for this thread. |
46 CloseHandle(GetCurrentThread()); | 46 MonitorWaitData::ThreadExit(); |
47 | 47 |
48 return 0; | 48 return 0; |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 int Thread::Start(ThreadStartFunction function, uword parameter) { | 52 int Thread::Start(ThreadStartFunction function, uword parameter) { |
53 ThreadStartData* start_data = new ThreadStartData(function, parameter); | 53 ThreadStartData* start_data = new ThreadStartData(function, parameter); |
54 uint32_t tid; | 54 uint32_t tid; |
55 uintptr_t thread = _beginthreadex(NULL, Thread::GetMaxStackSize(), | 55 uintptr_t thread = _beginthreadex(NULL, Thread::GetMaxStackSize(), |
56 ThreadEntry, start_data, 0, &tid); | 56 ThreadEntry, start_data, 0, &tid); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void Monitor::Enter() { | 166 void Monitor::Enter() { |
167 EnterCriticalSection(&data_.cs_); | 167 EnterCriticalSection(&data_.cs_); |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 void Monitor::Exit() { | 171 void Monitor::Exit() { |
172 LeaveCriticalSection(&data_.cs_); | 172 LeaveCriticalSection(&data_.cs_); |
173 } | 173 } |
174 | 174 |
175 | 175 |
| 176 void MonitorWaitData::ThreadExit() { |
| 177 uword raw_wait_data = |
| 178 Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); |
| 179 if (raw_wait_data != 0) { |
| 180 MonitorWaitData* wait_data = |
| 181 reinterpret_cast<MonitorWaitData*>(raw_wait_data); |
| 182 delete wait_data; |
| 183 } |
| 184 } |
| 185 |
| 186 |
176 void MonitorData::AddWaiter(MonitorWaitData* wait_data) { | 187 void MonitorData::AddWaiter(MonitorWaitData* wait_data) { |
177 // Add the MonitorWaitData object to the list of objects waiting for | 188 // Add the MonitorWaitData object to the list of objects waiting for |
178 // this monitor. | 189 // this monitor. |
179 EnterCriticalSection(&waiters_cs_); | 190 EnterCriticalSection(&waiters_cs_); |
180 if (waiters_tail_ == NULL) { | 191 if (waiters_tail_ == NULL) { |
181 ASSERT(waiters_head_ == NULL); | 192 ASSERT(waiters_head_ == NULL); |
182 waiters_head_ = waiters_tail_ = wait_data; | 193 waiters_head_ = waiters_tail_ = wait_data; |
183 } else { | 194 } else { |
184 waiters_tail_->next_ = wait_data; | 195 waiters_tail_->next_ = wait_data; |
185 waiters_tail_ = wait_data; | 196 waiters_tail_ = wait_data; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // timeout before we signal it, that object will get an extra | 345 // timeout before we signal it, that object will get an extra |
335 // signal. This will be treated as a spurious wake-up and is OK | 346 // signal. This will be treated as a spurious wake-up and is OK |
336 // since all uses of monitors should recheck the condition after a | 347 // since all uses of monitors should recheck the condition after a |
337 // Wait. | 348 // Wait. |
338 data_.SignalAndRemoveAllWaiters(); | 349 data_.SignalAndRemoveAllWaiters(); |
339 } | 350 } |
340 | 351 |
341 } // namespace dart | 352 } // namespace dart |
342 | 353 |
343 #endif // defined(TARGET_OS_WINDOWS) | 354 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |