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

Side by Side Diff: runtime/vm/thread_interrupter.h

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
(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 #ifndef VM_THREAD_INTERRUPTER_H_
6 #define VM_THREAD_INTERRUPTER_H_
7
8 #include "vm/allocation.h"
9 #include "vm/signal_handler.h"
10 #include "vm/thread.h"
11
12
13 namespace dart {
14
15 struct InterruptedThreadState {
16 ThreadId tid;
17 uintptr_t pc;
18 uintptr_t sp;
19 uintptr_t fp;
20 };
21
22 // When a thread is interrupted the thread specific interrupt
23 // callback will be invoked at the interrupt period. Each callback is given an
24 // InterruptedThreadState and the thread specific data pointer. When inside a
25 // thread interrupt callback doing any of the following
26 // is forbidden:
27 // * Accessing TLS.
28 // * Allocating memory.
29 // * Taking a lock.
30 typedef void (*ThreadInterruptCallback)(const InterruptedThreadState& state,
31 void* data);
32
33 class ThreadInterrupter : public AllStatic {
34 public:
35 static void InitOnce();
36 static void Shutdown();
37
38 // Delay between interrupts.
39 static void SetInterruptPeriod(intptr_t period);
40
41 // Register the currently running thread for interrupts. If the current thread
42 // is already registered, callback and data will be updated.
43 static void Register(ThreadInterruptCallback callback, void* data);
44 // Unregister the currently running thread for interrupts.
45 static void Unregister();
46
47 // Enable interrupts for this thread. Does not alter callback.
48 static void Enable();
49 // Disable interrupts for this thread. Does not alter callback.
50 static void Disable();
51
52 // These functions do not guarantee that no signals will be delivered when
53 // blocked.
54 static void BlockSignals();
55 static void UnblockSignals();
56
57 private:
58 static const intptr_t kMaxThreads = 4096;
59 static bool initialized_;
60 static bool shutdown_;
61 static bool thread_running_;
62 static ThreadId interrupter_thread_id_;
63 static Monitor* monitor_;
64 static Monitor* start_stop_monitor_;
65 static intptr_t interrupt_period_;
66 static ThreadLocalKey thread_state_key_;
67 // State stored per registered thread.
68 struct ThreadState {
69 ThreadId id;
70 ThreadInterruptCallback callback;
71 void* data;
72 };
73
74 static void UpdateStateObject(ThreadInterruptCallback callback, void* data);
75 static ThreadState* CurrentThreadState();
76 static void SetCurrentThreadState(ThreadState* state);
77
78 // Registered thread table.
79 static ThreadState** threads_;
80 static intptr_t threads_capacity_;
81 static intptr_t threads_size_;
82 static void _EnsureThreadStateCreated();
83 static void _Enable();
84 static void _Disable();
85 static void ResizeThreads(intptr_t new_capacity);
86 static void AddThread(ThreadId id);
87 static intptr_t FindThreadIndex(ThreadId id);
88 static ThreadState* RemoveThread(intptr_t i);
89
90 friend class ThreadInterrupterAndroid;
91 friend class ThreadInterrupterMacOS;
92 friend class ThreadInterrupterLinux;
93 friend class ThreadInterrupterWin;
94
95 static void InterruptThreads(int64_t current_time);
96 static void ThreadMain(uword parameters);
97
98 static void InstallSignalHandler();
99 };
100
101 void ThreadInterruptNoOp(const InterruptedThreadState& state, void* data);
102
103 } // namespace dart
104
105 #endif // VM_THREAD_INTERRUPTER_H_
OLDNEW
« runtime/bin/file.cc ('K') | « runtime/vm/thread.h ('k') | runtime/vm/thread_interrupter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698