summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/main.cpp4
-rw-r--r--src/buildtool/serve_api/serve_service/serve_server_implementation.cpp8
-rw-r--r--src/buildtool/serve_api/serve_service/serve_server_implementation.hpp8
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp12
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.hpp4
5 files changed, 23 insertions, 13 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 5f06cbad..72a5b060 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -843,11 +843,13 @@ auto main(int argc, char* argv[]) -> int {
}
if (arguments.cmd == SubCommand::kServe) {
+ std::mutex lock{};
auto serve_server =
ServeServerImpl::Create(arguments.service.interface,
arguments.service.port,
arguments.service.info_file,
- arguments.service.pid_file);
+ arguments.service.pid_file,
+ &lock);
if (serve_server) {
// Set up remote execution config.
auto remote_exec_config = CreateRemoteExecutionConfig(
diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
index fce3813b..54bb0c76 100644
--- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
+++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
@@ -76,9 +76,10 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool {
auto ServeServerImpl::Create(std::optional<std::string> interface,
std::optional<int> port,
std::optional<std::string> info_file,
- std::optional<std::string> pid_file) noexcept
+ std::optional<std::string> pid_file,
+ gsl::not_null<std::mutex*> const& lock) noexcept
-> std::optional<ServeServerImpl> {
- ServeServerImpl server;
+ auto server = ServeServerImpl(lock);
if (interface) {
server.interface_ = std::move(*interface);
}
@@ -182,7 +183,8 @@ auto ServeServerImpl::Run(
&serve_config,
&mr_apis,
is_compat ? &*secondary_local_context
- : local_context, // native_context
+ : local_context, // native_context
+ lock_,
is_compat ? &*local_context : nullptr // compat_context
};
diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
index d567c9a9..8f7f70dd 100644
--- a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
+++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
@@ -16,6 +16,7 @@
#define SERVE_SERVER_IMPLEMENTATION_HPP
#include <cstdint>
+#include <mutex>
#include <optional>
#include <string>
@@ -32,7 +33,8 @@ class ServeServerImpl final {
std::optional<std::string> interface,
std::optional<int> port,
std::optional<std::string> info_file,
- std::optional<std::string> pid_file) noexcept
+ std::optional<std::string> pid_file,
+ gsl::not_null<std::mutex*> const& lock) noexcept
-> std::optional<ServeServerImpl>;
~ServeServerImpl() noexcept = default;
@@ -58,7 +60,9 @@ class ServeServerImpl final {
bool with_execute) -> bool;
private:
- ServeServerImpl() noexcept = default;
+ explicit ServeServerImpl(gsl::not_null<std::mutex*> lock) noexcept
+ : lock_{lock} {};
+ gsl::not_null<std::mutex*> lock_;
std::string interface_{"127.0.0.1"};
int port_{0};
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index 8a45365d..f78c4f2c 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -576,7 +576,7 @@ auto SourceTreeService::ResolveContentTree(
});
{
// this is a non-thread-safe Git operation, so it must be guarded!
- std::unique_lock slock{mutex_};
+ std::unique_lock slock{*lock_};
// open real repository at Git CAS location
auto git_repo =
GitRepo::Open(native_context_->storage_config->GitRoot());
@@ -626,7 +626,7 @@ auto SourceTreeService::ArchiveImportToGit(
unpack_path,
/*commit_message=*/
fmt::format("Content of {} {}", archive_type, content),
- &mutex_);
+ lock_);
if (not res) {
// report the error
logger_->Emit(LogLevel::Error, "{}", res.error());
@@ -946,7 +946,7 @@ auto SourceTreeService::DistdirImportToGit(
*native_context_->storage_config,
tmp_path,
/*commit_message=*/fmt::format("Content of distdir {}", content_id),
- &mutex_);
+ lock_);
if (not res) {
// report the error
logger_->Emit(LogLevel::Error, "{}", res.error());
@@ -1564,7 +1564,7 @@ auto SourceTreeService::CheckRootTree(
*native_context_->storage_config,
tmp_dir->GetPath(),
/*commit_message=*/fmt::format("Content of tree {}", tree_id),
- &mutex_);
+ lock_);
if (not res) {
// report the error
logger_->Emit(LogLevel::Error, "{}", res.error());
@@ -1654,7 +1654,7 @@ auto SourceTreeService::GetRemoteTree(
tmp_dir->GetPath(),
/*commit_message=*/
fmt::format("Content of tree {}", remote_digest->hash()),
- &mutex_);
+ lock_);
if (not res) {
// report the error
logger_->Emit(LogLevel::Error, "{}", res.error());
@@ -1714,7 +1714,7 @@ auto SourceTreeService::ComputeTreeStructure(
*tree_digest,
known_repositories,
*native_context_->storage_config,
- &mutex_)) {
+ lock_)) {
tree_structure = std::move(from_local).value();
}
else {
diff --git a/src/buildtool/serve_api/serve_service/source_tree.hpp b/src/buildtool/serve_api/serve_service/source_tree.hpp
index ea93cb54..aaa55e87 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.hpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.hpp
@@ -66,9 +66,11 @@ class SourceTreeService final
gsl::not_null<RemoteServeConfig const*> const& serve_config,
gsl::not_null<ApiBundle const*> const& apis,
gsl::not_null<LocalContext const*> const& native_context,
+ gsl::not_null<std::mutex*> const& lock,
LocalContext const* compat_context = nullptr) noexcept
: serve_config_{*serve_config},
apis_{*apis},
+ lock_{lock},
native_context_{native_context},
compat_context_{compat_context} {}
@@ -147,9 +149,9 @@ class SourceTreeService final
private:
RemoteServeConfig const& serve_config_;
ApiBundle const& apis_;
+ gsl::not_null<std::mutex*> lock_;
gsl::not_null<LocalContext const*> native_context_;
LocalContext const* compat_context_;
- mutable std::mutex mutex_;
std::shared_ptr<Logger> logger_{std::make_shared<Logger>("serve-service")};
// symlinks resolver map
ResolveSymlinksMap resolve_symlinks_map_{CreateResolveSymlinksMap()};