Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: runtime/vm/thread_interrupter_android.cc

Issue 254383003: Small fixes for Android. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <sys/syscall.h> // NOLINT
9
8 #include "vm/signal_handler.h" 10 #include "vm/signal_handler.h"
9 #include "vm/thread_interrupter.h" 11 #include "vm/thread_interrupter.h"
10 12
11 namespace dart { 13 namespace dart {
12 14
13 DECLARE_FLAG(bool, thread_interrupter); 15 DECLARE_FLAG(bool, thread_interrupter);
14 DECLARE_FLAG(bool, trace_thread_interrupter); 16 DECLARE_FLAG(bool, trace_thread_interrupter);
15 17
16 class ThreadInterrupterAndroid : public AllStatic { 18 class ThreadInterrupterAndroid : public AllStatic {
17 public: 19 public:
18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, 20 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info,
19 void* context_) { 21 void* context_) {
20 if (signal != SIGPROF) { 22 if (signal != SIGPROF) {
21 return; 23 return;
22 } 24 }
23 InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState(); 25 InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState();
24 if ((state == NULL) || (state->callback == NULL)) { 26 if ((state == NULL) || (state->callback == NULL)) {
25 // No interrupter state or callback. 27 // No interrupter state or callback.
26 return; 28 return;
27 } 29 }
28 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); 30 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId()));
31 // Extract thread state.
32 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
33 mcontext_t mcontext = context->uc_mcontext;
34 InterruptedThreadState its;
35 its.tid = state->id;
36 its.pc = SignalHandler::GetProgramCounter(mcontext);
37 its.fp = SignalHandler::GetFramePointer(mcontext);
38 its.sp = SignalHandler::GetStackPointer(mcontext);
39 state->callback(its, state->data);
29 } 40 }
30 }; 41 };
31 42
32 43
33 void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) { 44 void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) {
34 if (FLAG_trace_thread_interrupter) { 45 if (FLAG_trace_thread_interrupter) {
35 OS::Print("ThreadInterrupter interrupting %p\n", 46 OS::Print("ThreadInterrupter interrupting %p\n",
36 reinterpret_cast<void*>(state->id)); 47 reinterpret_cast<void*>(state->id));
37 } 48 }
38 pthread_kill(state->id, SIGPROF); 49 syscall(__NR_tgkill, getpid(), state->id, SIGPROF);
39 } 50 }
40 51
41 52
42 void ThreadInterrupter::InstallSignalHandler() { 53 void ThreadInterrupter::InstallSignalHandler() {
43 SignalHandler::Install( 54 SignalHandler::Install(
44 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); 55 ThreadInterrupterAndroid::ThreadInterruptSignalHandler);
45 } 56 }
46 57
47 58
48 } // namespace dart 59 } // namespace dart
49 60
50 #endif // defined(TARGET_OS_ANDROID) 61 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« runtime/platform/thread_android.cc ('K') | « runtime/vm/signal_handler_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698