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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/profiler/profiler-listener.h » ('j') | no next file with comments »
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..94f7dbdfc0b8733bdff7cb2c4fa5184d4d2ecb85 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,16 @@ 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) \
+ 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 +177,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698