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

Side by Side Diff: src/code-events.h

Issue 2321073004: [profiler] Allow thread-safe access to add/remove code event observers. (Closed)
Patch Set: addressing the comment. Created 4 years, 3 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
« no previous file with comments | « no previous file | src/profiler/profiler-listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_CODE_EVENTS_H_ 5 #ifndef V8_CODE_EVENTS_H_
6 #define V8_CODE_EVENTS_H_ 6 #define V8_CODE_EVENTS_H_
7 7
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "src/base/platform/mutex.h"
10 #include "src/globals.h" 11 #include "src/globals.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 15
15 class AbstractCode; 16 class AbstractCode;
16 class Name; 17 class Name;
17 class SharedFunctionInfo; 18 class SharedFunctionInfo;
18 class String; 19 class String;
19 20
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 virtual void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) = 0; 108 virtual void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) = 0;
108 }; 109 };
109 110
110 class CodeEventDispatcher { 111 class CodeEventDispatcher {
111 public: 112 public:
112 using LogEventsAndTags = CodeEventListener::LogEventsAndTags; 113 using LogEventsAndTags = CodeEventListener::LogEventsAndTags;
113 114
114 CodeEventDispatcher() {} 115 CodeEventDispatcher() {}
115 116
116 bool AddListener(CodeEventListener* listener) { 117 bool AddListener(CodeEventListener* listener) {
118 base::LockGuard<base::Mutex> guard(&mutex_);
117 return listeners_.insert(listener).second; 119 return listeners_.insert(listener).second;
118 } 120 }
119 void RemoveListener(CodeEventListener* listener) { 121 void RemoveListener(CodeEventListener* listener) {
122 base::LockGuard<base::Mutex> guard(&mutex_);
120 listeners_.erase(listener); 123 listeners_.erase(listener);
121 } 124 }
122 125
123 #define CODE_EVENT_DISPATCH(code) \ 126 #define CODE_EVENT_DISPATCH(code) \
127 base::LockGuard<base::Mutex> guard(&mutex_); \
124 for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code 128 for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code
125 129
126 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, 130 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
127 const char* comment) { 131 const char* comment) {
128 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment)); 132 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
129 } 133 }
130 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name) { 134 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name) {
131 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name)); 135 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
132 } 136 }
133 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, 137 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared) { 170 void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared) {
167 CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared)); 171 CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared));
168 } 172 }
169 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { 173 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) {
170 CODE_EVENT_DISPATCH(CodeDeoptEvent(code, pc, fp_to_sp_delta)); 174 CODE_EVENT_DISPATCH(CodeDeoptEvent(code, pc, fp_to_sp_delta));
171 } 175 }
172 #undef CODE_EVENT_DISPATCH 176 #undef CODE_EVENT_DISPATCH
173 177
174 private: 178 private:
175 std::unordered_set<CodeEventListener*> listeners_; 179 std::unordered_set<CodeEventListener*> listeners_;
180 base::Mutex mutex_;
176 181
177 DISALLOW_COPY_AND_ASSIGN(CodeEventDispatcher); 182 DISALLOW_COPY_AND_ASSIGN(CodeEventDispatcher);
178 }; 183 };
179 184
180 } // namespace internal 185 } // namespace internal
181 } // namespace v8 186 } // namespace v8
182 187
183 #endif // V8_CODE_EVENTS_H_ 188 #endif // V8_CODE_EVENTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/profiler/profiler-listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698