Commit 1e937f66 authored by alph's avatar alph Committed by Commit bot

Allow thread-safe access to add/remove code event observers.

BUG=406277

Review-Url: https://codereview.chromium.org/2321073004
Cr-Commit-Position: refs/heads/master@{#39853}
parent e3222de3
......@@ -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);
};
......
......@@ -319,6 +319,7 @@ CodeEntry* ProfilerListener::NewCodeEntry(
}
void ProfilerListener::AddObserver(CodeEventObserver* observer) {
base::LockGuard<base::Mutex> guard(&mutex_);
if (std::find(observers_.begin(), observers_.end(), observer) !=
observers_.end())
return;
......@@ -326,6 +327,7 @@ void ProfilerListener::AddObserver(CodeEventObserver* observer) {
}
void ProfilerListener::RemoveObserver(CodeEventObserver* observer) {
base::LockGuard<base::Mutex> guard(&mutex_);
auto it = std::find(observers_.begin(), observers_.end(), observer);
if (it == observers_.end()) return;
observers_.erase(it);
......
......@@ -79,6 +79,7 @@ class ProfilerListener : public CodeEventListener {
void RecordDeoptInlinedFrames(CodeEntry* entry, AbstractCode* abstract_code);
Name* InferScriptName(Name* name, SharedFunctionInfo* info);
V8_INLINE void DispatchCodeEvent(const CodeEventsContainer& evt_rec) {
base::LockGuard<base::Mutex> guard(&mutex_);
for (auto observer : observers_) {
observer->CodeEventHandler(evt_rec);
}
......@@ -87,6 +88,7 @@ class ProfilerListener : public CodeEventListener {
StringsStorage function_and_resource_names_;
std::vector<CodeEntry*> code_entries_;
std::vector<CodeEventObserver*> observers_;
base::Mutex mutex_;
DISALLOW_COPY_AND_ASSIGN(ProfilerListener);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment