[wasm] Store AsyncCompileJob in unique_ptr
It was stored in a shared_ptr so far, which makes it more difficult to reason about life times. Since there is always exactly one owner of the AsyncCompileJob, a unique_ptr actually suffices. R=ahaas@chromium.org Change-Id: If94c9091889ad05325c559a97e9a9ffeee8d450c Reviewed-on: https://chromium-review.googlesource.com/968604 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#52052}
This commit is contained in:
parent
014f459047
commit
fed003c624
@ -3,7 +3,6 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "src/wasm/compilation-manager.h"
|
#include "src/wasm/compilation-manager.h"
|
||||||
#include "src/base/template-utils.h"
|
|
||||||
#include "src/wasm/module-compiler.h"
|
#include "src/wasm/module-compiler.h"
|
||||||
|
|
||||||
#include "src/objects-inl.h"
|
#include "src/objects-inl.h"
|
||||||
@ -15,10 +14,11 @@ namespace wasm {
|
|||||||
AsyncCompileJob* CompilationManager::CreateAsyncCompileJob(
|
AsyncCompileJob* CompilationManager::CreateAsyncCompileJob(
|
||||||
Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, size_t length,
|
Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, size_t length,
|
||||||
Handle<Context> context, Handle<JSPromise> promise) {
|
Handle<Context> context, Handle<JSPromise> promise) {
|
||||||
std::shared_ptr<AsyncCompileJob> job(new AsyncCompileJob(
|
AsyncCompileJob* job = new AsyncCompileJob(isolate, std::move(bytes_copy),
|
||||||
isolate, std::move(bytes_copy), length, context, promise));
|
length, context, promise);
|
||||||
jobs_.insert({job.get(), job});
|
// Pass ownership to the unique_ptr in {jobs_}.
|
||||||
return job.get();
|
jobs_[job] = std::unique_ptr<AsyncCompileJob>(job);
|
||||||
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilationManager::StartAsyncCompileJob(
|
void CompilationManager::StartAsyncCompileJob(
|
||||||
@ -36,11 +36,11 @@ std::shared_ptr<StreamingDecoder> CompilationManager::StartStreamingCompilation(
|
|||||||
return job->CreateStreamingDecoder();
|
return job->CreateStreamingDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AsyncCompileJob> CompilationManager::RemoveJob(
|
std::unique_ptr<AsyncCompileJob> CompilationManager::RemoveJob(
|
||||||
AsyncCompileJob* job) {
|
AsyncCompileJob* job) {
|
||||||
auto item = jobs_.find(job);
|
auto item = jobs_.find(job);
|
||||||
DCHECK(item != jobs_.end());
|
DCHECK(item != jobs_.end());
|
||||||
std::shared_ptr<AsyncCompileJob> result = std::move(item->second);
|
std::unique_ptr<AsyncCompileJob> result = std::move(item->second);
|
||||||
jobs_.erase(item);
|
jobs_.erase(item);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -50,10 +50,11 @@ void CompilationManager::TearDown() { jobs_.clear(); }
|
|||||||
void CompilationManager::AbortAllJobs() {
|
void CompilationManager::AbortAllJobs() {
|
||||||
// Iterate over a copy of {jobs_}, because {job->Abort} modifies {jobs_}.
|
// Iterate over a copy of {jobs_}, because {job->Abort} modifies {jobs_}.
|
||||||
std::vector<AsyncCompileJob*> copy;
|
std::vector<AsyncCompileJob*> copy;
|
||||||
|
copy.reserve(jobs_.size());
|
||||||
|
|
||||||
for (auto entry : jobs_) copy.push_back(entry.first);
|
for (auto& entry : jobs_) copy.push_back(entry.first);
|
||||||
|
|
||||||
for (auto job : copy) job->Abort();
|
for (auto* job : copy) job->Abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace wasm
|
} // namespace wasm
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#ifndef V8_WASM_COMPILATION_MANAGER_H_
|
#ifndef V8_WASM_COMPILATION_MANAGER_H_
|
||||||
#define V8_WASM_COMPILATION_MANAGER_H_
|
#define V8_WASM_COMPILATION_MANAGER_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "src/handles.h"
|
#include "src/handles.h"
|
||||||
#include "src/isolate.h"
|
#include "src/isolate.h"
|
||||||
@ -31,7 +31,7 @@ class CompilationManager {
|
|||||||
Isolate* isolate, Handle<Context> context, Handle<JSPromise> promise);
|
Isolate* isolate, Handle<Context> context, Handle<JSPromise> promise);
|
||||||
|
|
||||||
// Remove {job} from the list of active compile jobs.
|
// Remove {job} from the list of active compile jobs.
|
||||||
std::shared_ptr<AsyncCompileJob> RemoveJob(AsyncCompileJob* job);
|
std::unique_ptr<AsyncCompileJob> RemoveJob(AsyncCompileJob* job);
|
||||||
|
|
||||||
// Cancel all AsyncCompileJobs and delete their state immediately.
|
// Cancel all AsyncCompileJobs and delete their state immediately.
|
||||||
void TearDown();
|
void TearDown();
|
||||||
@ -52,7 +52,7 @@ class CompilationManager {
|
|||||||
|
|
||||||
// We use an AsyncCompileJob as the key for itself so that we can delete the
|
// We use an AsyncCompileJob as the key for itself so that we can delete the
|
||||||
// job from the map when it is finished.
|
// job from the map when it is finished.
|
||||||
std::unordered_map<AsyncCompileJob*, std::shared_ptr<AsyncCompileJob>> jobs_;
|
std::unordered_map<AsyncCompileJob*, std::unique_ptr<AsyncCompileJob>> jobs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wasm
|
} // namespace wasm
|
||||||
|
Loading…
Reference in New Issue
Block a user