| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/os.h" | 9 #include "vm/os.h" |
| 10 #include "vm/thread_interrupter.h" | 10 #include "vm/thread_interrupter.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 state->dsp = static_cast<uintptr_t>(context.Rsp); | 44 state->dsp = static_cast<uintptr_t>(context.Rsp); |
| 45 #else | 45 #else |
| 46 #error Unsupported architecture. | 46 #error Unsupported architecture. |
| 47 #endif | 47 #endif |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 static void Interrupt(InterruptableThreadState* state) { | 54 static void Interrupt(Thread* thread) { |
| 55 ASSERT(!OSThread::Compare(GetCurrentThreadId(), state->id)); | 55 ASSERT(!OSThread::Compare(GetCurrentThreadId(), thread->id())); |
| 56 HANDLE handle = OpenThread(THREAD_GET_CONTEXT | | 56 HANDLE handle = OpenThread(THREAD_GET_CONTEXT | |
| 57 THREAD_QUERY_INFORMATION | | 57 THREAD_QUERY_INFORMATION | |
| 58 THREAD_SUSPEND_RESUME, | 58 THREAD_SUSPEND_RESUME, |
| 59 false, | 59 false, |
| 60 state->id); | 60 thread->id()); |
| 61 ASSERT(handle != NULL); | 61 ASSERT(handle != NULL); |
| 62 DWORD result = SuspendThread(handle); | 62 DWORD result = SuspendThread(handle); |
| 63 if (result == kThreadError) { | 63 if (result == kThreadError) { |
| 64 if (FLAG_trace_thread_interrupter) { | 64 if (FLAG_trace_thread_interrupter) { |
| 65 OS::Print("ThreadInterrupted failed to suspend thread %p\n", | 65 OS::Print("ThreadInterrupter failed to suspend thread %p\n", |
| 66 reinterpret_cast<void*>(state->id)); | 66 reinterpret_cast<void*>(thread->id())); |
| 67 } | 67 } |
| 68 CloseHandle(handle); | 68 CloseHandle(handle); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 InterruptedThreadState its; | 71 InterruptedThreadState its; |
| 72 its.tid = state->id; | 72 its.tid = thread->id(); |
| 73 if (!GrabRegisters(handle, &its)) { | 73 if (!GrabRegisters(handle, &its)) { |
| 74 // Failed to get thread registers. | 74 // Failed to get thread registers. |
| 75 ResumeThread(handle); | 75 ResumeThread(handle); |
| 76 if (FLAG_trace_thread_interrupter) { | 76 if (FLAG_trace_thread_interrupter) { |
| 77 OS::Print("ThreadInterrupted failed to get registers for %p\n", | 77 OS::Print("ThreadInterrupter failed to get registers for %p\n", |
| 78 reinterpret_cast<void*>(state->id)); | 78 reinterpret_cast<void*>(thread->id())); |
| 79 } | 79 } |
| 80 CloseHandle(handle); | 80 CloseHandle(handle); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 if (state->callback == NULL) { | 83 ThreadInterruptCallback callback = NULL; |
| 84 // No callback registered. | 84 void* callback_data = NULL; |
| 85 ResumeThread(handle); | 85 if (thread->IsThreadInterrupterEnabled(&callback, &callback_data)) { |
| 86 CloseHandle(handle); | 86 callback(its, callback_data); |
| 87 return; | |
| 88 } | 87 } |
| 89 state->callback(its, state->data); | |
| 90 ResumeThread(handle); | 88 ResumeThread(handle); |
| 91 CloseHandle(handle); | 89 CloseHandle(handle); |
| 92 } | 90 } |
| 93 }; | 91 }; |
| 94 | 92 |
| 95 | 93 |
| 96 void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) { | 94 void ThreadInterrupter::InterruptThread(Thread* thread) { |
| 97 if (FLAG_trace_thread_interrupter) { | 95 if (FLAG_trace_thread_interrupter) { |
| 98 OS::Print("ThreadInterrupter suspending %p\n", | 96 OS::Print("ThreadInterrupter suspending %p\n", |
| 99 reinterpret_cast<void*>(state->id)); | 97 reinterpret_cast<void*>(thread->id())); |
| 100 } | 98 } |
| 101 ThreadInterrupterWin::Interrupt(state); | 99 ThreadInterrupterWin::Interrupt(thread); |
| 102 if (FLAG_trace_thread_interrupter) { | 100 if (FLAG_trace_thread_interrupter) { |
| 103 OS::Print("ThreadInterrupter resuming %p\n", | 101 OS::Print("ThreadInterrupter resuming %p\n", |
| 104 reinterpret_cast<void*>(state->id)); | 102 reinterpret_cast<void*>(thread->id())); |
| 105 } | 103 } |
| 106 } | 104 } |
| 107 | 105 |
| 108 | 106 |
| 109 void ThreadInterrupter::InstallSignalHandler() { | 107 void ThreadInterrupter::InstallSignalHandler() { |
| 110 // Nothing to do on Windows. | 108 // Nothing to do on Windows. |
| 111 } | 109 } |
| 112 | 110 |
| 113 | 111 |
| 114 void ThreadInterrupter::RemoveSignalHandler() { | 112 void ThreadInterrupter::RemoveSignalHandler() { |
| 115 // Nothing to do on Windows. | 113 // Nothing to do on Windows. |
| 116 } | 114 } |
| 117 | 115 |
| 118 | 116 |
| 119 } // namespace dart | 117 } // namespace dart |
| 120 | 118 |
| 121 #endif // defined(TARGET_OS_WINDOWS) | 119 #endif // defined(TARGET_OS_WINDOWS) |
| 122 | 120 |
| OLD | NEW |