Skip to content

Commit 94e6f08

Browse files
addaleaxdanielleadams
authored andcommitted
src: mark generated snapshot_data as const
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>
1 parent bbaca84 commit 94e6f08

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

src/node_snapshot_builder.h

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class NODE_EXTERN_PRIVATE SnapshotBuilder {
3131
v8::Isolate::CreateParams* params);
3232

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

3836
static std::unique_ptr<ExternalReferenceRegistry> registry_;

src/node_snapshotable.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ static void WriteCodeCacheInitializer(std::ostream* ss, const std::string& id) {
978978
*ss << " },\n";
979979
}
980980

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

1007-
ss << R"(SnapshotData snapshot_data {
1007+
ss << R"(const SnapshotData snapshot_data {
10081008
// -- data_ownership begins --
10091009
SnapshotData::DataOwnership::kNotOwned,
10101010
// -- data_ownership ends --
@@ -1036,7 +1036,6 @@ static const int v8_snapshot_blob_size = )"
10361036
};
10371037
10381038
const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() {
1039-
Mutex::ScopedLock lock(snapshot_data_mutex_);
10401039
return &snapshot_data;
10411040
}
10421041
} // namespace node
@@ -1053,8 +1052,6 @@ static void ResetContextSettingsBeforeSnapshot(Local<Context> context) {
10531052
context->AllowCodeGenerationFromStrings(true);
10541053
}
10551054

1056-
Mutex SnapshotBuilder::snapshot_data_mutex_;
1057-
10581055
const std::vector<intptr_t>& SnapshotBuilder::CollectExternalReferences() {
10591056
static auto registry = std::make_unique<ExternalReferenceRegistry>();
10601057
return registry->external_references();

0 commit comments

Comments
 (0)