Skip to content

Commit

Permalink
src: mark generated snapshot_data as const
Browse files Browse the repository at this point in the history
This renders the mutex protecting it unnecessary, since mutexes
only need to protect concurrent accesses to mutable data.

PR-URL: #45786
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
addaleax authored Dec 10, 2022
1 parent 2ec4189 commit 94d23f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/node_snapshot_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class NODE_EXTERN_PRIVATE SnapshotBuilder {
v8::Isolate::CreateParams* params);

private:
// Used to synchronize access to the snapshot data
static Mutex snapshot_data_mutex_;
static const std::vector<intptr_t>& CollectExternalReferences();

static std::unique_ptr<ExternalReferenceRegistry> registry_;
Expand Down
7 changes: 2 additions & 5 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ static void WriteCodeCacheInitializer(std::ostream* ss, const std::string& id) {
*ss << " },\n";
}

void FormatBlob(std::ostream& ss, SnapshotData* data) {
void FormatBlob(std::ostream& ss, const SnapshotData* data) {
ss << R"(#include <cstddef>
#include "env.h"
#include "node_snapshot_builder.h"
Expand All @@ -1004,7 +1004,7 @@ static const int v8_snapshot_blob_size = )"
WriteStaticCodeCacheData(&ss, item);
}

ss << R"(SnapshotData snapshot_data {
ss << R"(const SnapshotData snapshot_data {
// -- data_ownership begins --
SnapshotData::DataOwnership::kNotOwned,
// -- data_ownership ends --
Expand Down Expand Up @@ -1036,7 +1036,6 @@ static const int v8_snapshot_blob_size = )"
};
const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() {
Mutex::ScopedLock lock(snapshot_data_mutex_);
return &snapshot_data;
}
} // namespace node
Expand All @@ -1053,8 +1052,6 @@ static void ResetContextSettingsBeforeSnapshot(Local<Context> context) {
context->AllowCodeGenerationFromStrings(true);
}

Mutex SnapshotBuilder::snapshot_data_mutex_;

const std::vector<intptr_t>& SnapshotBuilder::CollectExternalReferences() {
static auto registry = std::make_unique<ExternalReferenceRegistry>();
return registry->external_references();
Expand Down

0 comments on commit 94d23f5

Please sign in to comment.