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

Unified Diff: src/code-events.h

Issue 2321073004: [profiler] Allow thread-safe access to add/remove code event observers. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/profiler/profiler-listener.h » ('j') | src/profiler/profiler-listener.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/code-events.h
diff --git a/src/code-events.h b/src/code-events.h
index 9ae1caeb373ee4996016b7b59a59b24c281e793e..da04f15fe4e67865d63bb3b63f9e51cc4dbe3aaf 100644
--- a/src/code-events.h
+++ b/src/code-events.h
@@ -7,6 +7,7 @@
#include <unordered_set>
+#include "src/base/platform/mutex.h"
#include "src/globals.h"
namespace v8 {
@@ -114,13 +115,17 @@ class CodeEventDispatcher {
CodeEventDispatcher() {}
bool AddListener(CodeEventListener* listener) {
+ base::LockGuard<base::Mutex> guard(&mutex_);
return listeners_.insert(listener).second;
}
void RemoveListener(CodeEventListener* listener) {
+ base::LockGuard<base::Mutex> guard(&mutex_);
listeners_.erase(listener);
}
-#define CODE_EVENT_DISPATCH(code) \
+#define CODE_EVENT_DISPATCH(code) \
+ if (listeners_.empty()) return; \
+ base::LockGuard<base::Mutex> guard(&mutex_); \
for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
@@ -173,6 +178,7 @@ class CodeEventDispatcher {
private:
std::unordered_set<CodeEventListener*> listeners_;
+ base::Mutex mutex_;
DISALLOW_COPY_AND_ASSIGN(CodeEventDispatcher);
};
« no previous file with comments | « no previous file | src/profiler/profiler-listener.h » ('j') | src/profiler/profiler-listener.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698