Skip to content

Commit e565d42

Browse files
committed
Use a single lock in indexing dispatches
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 4fc6247 commit e565d42

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/build/build.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ auto Build::refresh(const std::filesystem::path &path) -> void {
124124
this->entries_[path.native()].file_mark = value;
125125
}
126126

127-
auto Build::track(const std::filesystem::path &path) -> void {
127+
auto Build::track_unsafe(const std::filesystem::path &path) -> void {
128128
assert(path.is_absolute());
129129
const auto &path_string{path.native()};
130-
std::unique_lock lock{this->mutex};
131130
this->entries_[path_string].tracked = true;
132131
auto parent_key{path_string};
133132
while (true) {
@@ -147,6 +146,11 @@ auto Build::track(const std::filesystem::path &path) -> void {
147146
}
148147
}
149148

149+
auto Build::track(const std::filesystem::path &path) -> void {
150+
std::unique_lock lock{this->mutex};
151+
this->track_unsafe(path);
152+
}
153+
150154
auto Build::is_untracked_file(const std::filesystem::path &path) const -> bool {
151155
std::shared_lock lock{this->mutex};
152156
const auto match{this->entries_.find(path.native())};

src/build/include/sourcemeta/one/build.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <array> // std::array
1111
#include <filesystem> // std::filesystem
1212
#include <functional> // std::function, std::reference_wrapper, std::cref
13+
#include <mutex> // std::unique_lock
1314
#include <optional> // std::optional
1415
#include <shared_mutex> // std::shared_mutex, std::shared_lock
1516
#include <string> // std::string
@@ -50,7 +51,7 @@ class SOURCEMETA_ONE_BUILD_EXPORT Build {
5051
const std::vector<std::filesystem::path> &dependencies)
5152
-> bool {
5253
const auto &destination_string{destination.native()};
53-
std::shared_lock lock{this->mutex};
54+
std::unique_lock lock{this->mutex};
5455
const auto cached_match{this->entries_.find(destination_string)};
5556
if (cached_match != this->entries_.end()) {
5657
const auto &entry{cached_match->second};
@@ -69,8 +70,7 @@ class SOURCEMETA_ONE_BUILD_EXPORT Build {
6970
}
7071

7172
if (this->dispatch_is_cached(entry, static_dependencies_match)) {
72-
lock.unlock();
73-
this->track(destination);
73+
this->track_unsafe(destination);
7474
return false;
7575
}
7676
}
@@ -107,7 +107,7 @@ class SOURCEMETA_ONE_BUILD_EXPORT Build {
107107
const Context &context, const DependencyTypes &...dependencies)
108108
-> bool {
109109
const auto &destination_string{destination.native()};
110-
std::shared_lock lock{this->mutex};
110+
std::unique_lock lock{this->mutex};
111111
const auto cached_match{this->entries_.find(destination_string)};
112112
if (cached_match != this->entries_.end()) {
113113
const auto &entry{cached_match->second};
@@ -131,8 +131,7 @@ class SOURCEMETA_ONE_BUILD_EXPORT Build {
131131
}
132132

133133
if (this->dispatch_is_cached(entry, static_dependencies_match)) {
134-
lock.unlock();
135-
this->track(destination);
134+
this->track_unsafe(destination);
136135
return false;
137136
}
138137
}
@@ -187,6 +186,7 @@ class SOURCEMETA_ONE_BUILD_EXPORT Build {
187186
std::vector<std::filesystem::path> &&static_dependencies,
188187
std::vector<std::filesystem::path> &&dynamic_dependencies)
189188
-> void;
189+
auto track_unsafe(const std::filesystem::path &path) -> void;
190190

191191
std::filesystem::path root;
192192
std::string root_string;

0 commit comments

Comments
 (0)