diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-15 10:19:16 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-19 09:50:37 +0200 |
commit | a5f048e3b2504959994cc9545a70fde01b70d99a (patch) | |
tree | 42ef3e92abdba766e4c56ed8e0dbfff37de22416 /src/buildtool/execution_api/execution_service/operation_cache.hpp | |
parent | 1acde5fa1f37b8e4856f96aba092a38faaac737f (diff) | |
download | justbuild-a5f048e3b2504959994cc9545a70fde01b70d99a.tar.gz |
Make OperationCache a general class, not singleton
As it is used by just execute only, instantiate it inside the
ExecutionServer, which reads and writes to the cache map, and pass
a const ref to OperationsServer, which only queries.
Diffstat (limited to 'src/buildtool/execution_api/execution_service/operation_cache.hpp')
-rw-r--r-- | src/buildtool/execution_api/execution_service/operation_cache.hpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/buildtool/execution_api/execution_service/operation_cache.hpp b/src/buildtool/execution_api/execution_service/operation_cache.hpp index 317bade4..a53aff98 100644 --- a/src/buildtool/execution_api/execution_service/operation_cache.hpp +++ b/src/buildtool/execution_api/execution_service/operation_cache.hpp @@ -29,14 +29,10 @@ #include "google/longrunning/operations.pb.h" #include "google/protobuf/timestamp.pb.h" -class OperationCache { +class OperationCache final { using Operation = ::google::longrunning::Operation; public: - [[nodiscard]] static auto Instance() -> OperationCache& { - static OperationCache x; - return x; - } OperationCache() noexcept = default; ~OperationCache() noexcept = default; @@ -45,18 +41,16 @@ class OperationCache { OperationCache(OperationCache&&) = delete; auto operator=(OperationCache&&) -> OperationCache& = delete; - static void Set(std::string const& action, Operation const& op) { - Instance().SetInternal(action, op); + void Set(std::string const& action, Operation const& op) { + SetInternal(action, op); } - [[nodiscard]] static auto Query(std::string const& x) noexcept + [[nodiscard]] auto Query(std::string const& x) const noexcept -> std::optional<Operation> { - return Instance().QueryInternal(x); + return QueryInternal(x); } - static void SetExponent(std::uint8_t x) noexcept { - Instance().threshold_ = 1U << x; - } + void SetExponent(std::uint8_t x) noexcept { threshold_ = 1U << x; } private: mutable std::shared_mutex mutex_; |