diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-11-20 14:24:50 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-11-20 14:30:46 +0100 |
commit | dfb7ad5c7d5dcca13d9728534434079a2b60bdea (patch) | |
tree | 1877539cfcc8d529d611f4e9934344b97fe0cdb9 /src | |
parent | 9c3d4539b820b34ca112dedbaf2ed5262c003ace (diff) | |
download | justbuild-dfb7ad5c7d5dcca13d9728534434079a2b60bdea.tar.gz |
Serve service: properly lock git operations against each other
... by using an exclusive lock. A lock of which only ever shared instances
are requested has no synchronisation effect. Fix this.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.cpp | 5 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.hpp | 4 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp index 92480919..dfbb04f5 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.cpp +++ b/src/buildtool/serve_api/serve_service/source_tree.cpp @@ -18,7 +18,6 @@ #include <algorithm> #include <functional> -#include <shared_mutex> #include <vector> #include "fmt/core.h" @@ -552,7 +551,7 @@ auto SourceTreeService::ResolveContentTree( }); { // this is a non-thread-safe Git operation, so it must be guarded! - std::shared_lock slock{mutex_}; + std::unique_lock slock{mutex_}; // open real repository at Git CAS location auto git_repo = GitRepo::Open(native_context_->storage_config->GitRoot()); @@ -674,7 +673,7 @@ auto SourceTreeService::CommonImportToGit( // tag commit and keep it in Git CAS { // this is a non-thread-safe Git operation, so it must be guarded! - std::shared_lock slock{mutex_}; + std::unique_lock slock{mutex_}; // open real repository at Git CAS location auto git_repo = GitRepo::Open(native_context_->storage_config->GitRoot()); diff --git a/src/buildtool/serve_api/serve_service/source_tree.hpp b/src/buildtool/serve_api/serve_service/source_tree.hpp index 670d190f..7b3d3cac 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.hpp +++ b/src/buildtool/serve_api/serve_service/source_tree.hpp @@ -17,8 +17,8 @@ #include <filesystem> #include <memory> +#include <mutex> #include <optional> -#include <shared_mutex> #include <string> #include <type_traits> #include <unordered_map> @@ -137,7 +137,7 @@ class SourceTreeService final ApiBundle const& apis_; gsl::not_null<LocalContext const*> native_context_; LocalContext const* compat_context_; - mutable std::shared_mutex mutex_; + mutable std::mutex mutex_; std::shared_ptr<Logger> logger_{std::make_shared<Logger>("serve-service")}; // symlinks resolver map ResolveSymlinksMap resolve_symlinks_map_{CreateResolveSymlinksMap()}; |