| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "vm/signal_handler.h" | 8 #include "vm/signal_handler.h" |
| 9 #include "vm/thread_interrupter.h" | 9 #include "vm/thread_interrupter.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DECLARE_FLAG(bool, thread_interrupter); | 13 DECLARE_FLAG(bool, thread_interrupter); |
| 14 DECLARE_FLAG(bool, trace_thread_interrupter); | 14 DECLARE_FLAG(bool, trace_thread_interrupter); |
| 15 | 15 |
| 16 class ThreadInterrupterAndroid : public AllStatic { | 16 class ThreadInterrupterAndroid : public AllStatic { |
| 17 public: | 17 public: |
| 18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, | 18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, |
| 19 void* context_) { | 19 void* context_) { |
| 20 if (signal != SIGPROF) { | 20 if (signal != SIGPROF) { |
| 21 return; | 21 return; |
| 22 } | 22 } |
| 23 ThreadInterrupter::ThreadState* state = | 23 InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState(); |
| 24 ThreadInterrupter::CurrentThreadState(); | |
| 25 if ((state == NULL) || (state->callback == NULL)) { | 24 if ((state == NULL) || (state->callback == NULL)) { |
| 26 // No interrupter state or callback. | 25 // No interrupter state or callback. |
| 27 return; | 26 return; |
| 28 } | 27 } |
| 29 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); | 28 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); |
| 30 } | 29 } |
| 31 }; | 30 }; |
| 32 | 31 |
| 33 | 32 |
| 34 void ThreadInterrupter::InterruptThreads(int64_t current_time) { | 33 void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) { |
| 35 for (intptr_t i = 0; i < threads_size_; i++) { | 34 if (FLAG_trace_thread_interrupter) { |
| 36 ThreadState* state = threads_[i]; | 35 OS::Print("ThreadInterrupter interrupting %p\n", |
| 37 ASSERT(state->id != Thread::kInvalidThreadId); | 36 reinterpret_cast<void*>(state->id)); |
| 38 if (FLAG_trace_thread_interrupter) { | |
| 39 OS::Print("ThreadInterrupter interrupting %p\n", | |
| 40 reinterpret_cast<void*>(state->id)); | |
| 41 } | |
| 42 pthread_kill(state->id, SIGPROF); | |
| 43 } | 37 } |
| 38 pthread_kill(state->id, SIGPROF); |
| 44 } | 39 } |
| 45 | 40 |
| 46 | 41 |
| 47 void ThreadInterrupter::InstallSignalHandler() { | 42 void ThreadInterrupter::InstallSignalHandler() { |
| 48 SignalHandler::Install( | 43 SignalHandler::Install( |
| 49 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); | 44 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); |
| 50 } | 45 } |
| 51 | 46 |
| 52 | 47 |
| 53 } // namespace dart | 48 } // namespace dart |
| 54 | 49 |
| 55 #endif // defined(TARGET_OS_ANDROID) | 50 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |