OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) |
| 7 |
| 8 #include "vm/thread_interrupter.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 DECLARE_FLAG(bool, thread_interrupter); |
| 13 DECLARE_FLAG(bool, trace_thread_interrupter); |
| 14 |
| 15 class ThreadInterrupterAndroid : public AllStatic { |
| 16 public: |
| 17 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, |
| 18 void* context_) { |
| 19 if (signal != SIGPROF) { |
| 20 return; |
| 21 } |
| 22 ThreadInterrupter::ThreadState* state = |
| 23 ThreadInterrupter::CurrentThreadState(); |
| 24 if ((state == NULL) || (state->callback == NULL)) { |
| 25 // No interrupter state or callback. |
| 26 return; |
| 27 } |
| 28 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); |
| 29 // Extract thread state. |
| 30 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); |
| 31 mcontext_t mcontext = context->uc_mcontext; |
| 32 InterruptedThreadState its; |
| 33 its.tid = state->id; |
| 34 its.pc = SignalHandler::GetProgramCounter(mcontext); |
| 35 its.fp = SignalHandler::GetFramePointer(mcontext); |
| 36 its.sp = SignalHandler::GetStackPointer(mcontext); |
| 37 state->callback(its, state->data); |
| 38 } |
| 39 }; |
| 40 |
| 41 |
| 42 void ThreadInterrupter::InterruptThreads(int64_t current_time) { |
| 43 for (intptr_t i = 0; i < threads_size_; i++) { |
| 44 ThreadState* state = threads_[i]; |
| 45 ASSERT(state->id != Thread::kInvalidThreadId); |
| 46 if (FLAG_trace_thread_interrupter) { |
| 47 OS::Print("ThreadInterrupter interrupting %p\n", |
| 48 reinterpret_cast<void*>(state->id)); |
| 49 } |
| 50 pthread_kill(state->id, SIGPROF); |
| 51 } |
| 52 } |
| 53 |
| 54 |
| 55 void ThreadInterrupter::InstallSignalHandler() { |
| 56 SignalHandler::Install( |
| 57 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); |
| 58 } |
| 59 |
| 60 |
| 61 } // namespace dart |
| 62 |
| 63 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |