Remove a use of absl/synchronization from Cobalt.
absl/synchronization is banned in Fuchsia:
https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/languages/c-cpp/library_restrictions.md#third_party_absl_cpp
Replace it with src/lib/util/protected_fields.h instead.
Change-Id: Ic41bce7c63c5ee66b2e772247e66f0cf9af50001
diff --git a/src/bin/test_app/BUILD.gn b/src/bin/test_app/BUILD.gn
index 4ec99b6..5a557c3 100644
--- a/src/bin/test_app/BUILD.gn
+++ b/src/bin/test_app/BUILD.gn
@@ -63,7 +63,6 @@
"$cobalt_root/src/bin/test_app/test_registry",
"$cobalt_root/src/logger:logger_test_utils",
"$cobalt_root/src/logger:project_context_factory",
- "//third_party/abseil-cpp/absl/synchronization",
"//third_party/gflags",
"//third_party/googletest:gtest",
"//third_party/tink/cc/util:status",
diff --git a/src/system_data/BUILD.gn b/src/system_data/BUILD.gn
index 82e2094..6c8a43b 100644
--- a/src/system_data/BUILD.gn
+++ b/src/system_data/BUILD.gn
@@ -33,8 +33,8 @@
configs += [ "$cobalt_root:cobalt_config" ]
deps = [
"$cobalt_root/src:logging",
+ "$cobalt_root/src/lib/util:protected_fields",
"//third_party/abseil-cpp",
- "//third_party/abseil-cpp/absl/synchronization",
]
public_deps = [
"$cobalt_root/src/pb",
diff --git a/src/system_data/system_data.h b/src/system_data/system_data.h
index 28e8b35..d1d3d4d 100644
--- a/src/system_data/system_data.h
+++ b/src/system_data/system_data.h
@@ -11,9 +11,9 @@
#include <utility>
#include <vector>
+#include "src/lib/util/protected_fields.h"
#include "src/pb/observation_batch.pb.h"
#include "src/registry/metric_definition.pb.h"
-#include "third_party/abseil-cpp/absl/synchronization/mutex.h"
namespace cobalt::system_data {
@@ -64,18 +64,18 @@
~SystemData() override = default;
// Returns a vector with all experiments the system has a notion of.
- const std::vector<Experiment>& experiments() const override LOCKS_EXCLUDED(experiments_mutex_) {
- absl::ReaderMutexLock lock(&experiments_mutex_);
- return experiments_;
+ const std::vector<Experiment>& experiments() const override {
+ auto unprotected_experiments = protected_experiments_.const_lock();
+ return unprotected_experiments->experiments;
}
// Returns the SystemProfile for the current system.
const SystemProfile& system_profile() const override { return system_profile_; }
// Resets the experiment state to the one provided.
- void SetExperimentState(std::vector<Experiment> experiments) LOCKS_EXCLUDED(experiments_mutex_) {
- absl::WriterMutexLock lock(&experiments_mutex_);
- experiments_ = std::move(experiments);
+ void SetExperimentState(std::vector<Experiment> experiments) {
+ auto unprotected_experiments = protected_experiments_.lock();
+ unprotected_experiments->experiments = std::move(experiments);
}
// Resets the current channel value.
@@ -92,8 +92,10 @@
void PopulateSystemProfile();
SystemProfile system_profile_;
- mutable absl::Mutex experiments_mutex_;
- std::vector<Experiment> experiments_ GUARDED_BY(experiments_mutex_);
+ struct UnprotectedExperiments {
+ std::vector<Experiment> experiments;
+ };
+ util::RWProtectedFields<UnprotectedExperiments> protected_experiments_;
ReleaseStage release_stage_;
};