mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Fix build warnings.
PiperOrigin-RevId: 877501913
This commit is contained in:
committed by
Copybara-Service
parent
657591bce4
commit
65276b6891
@@ -128,6 +128,7 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
":base",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include <memory>
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -28,7 +31,7 @@ CancellationFlag::CancellationFlag(bool cancelled) {
|
||||
}
|
||||
|
||||
CancellationFlag::~CancellationFlag() {
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
listeners_.clear();
|
||||
}
|
||||
|
||||
@@ -40,7 +43,7 @@ void CancellationFlag::Cancel() {
|
||||
|
||||
absl::flat_hash_set<CancelListener *> listeners;
|
||||
{
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
if (cancelled_) {
|
||||
// Someone already cancelled. Return immediately.
|
||||
return;
|
||||
@@ -62,14 +65,14 @@ void CancellationFlag::Uncancel() {
|
||||
}
|
||||
|
||||
{
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
assert(cancelled_);
|
||||
cancelled_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CancellationFlag::Cancelled() const {
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
|
||||
// Return false as no-op if feature flag is not enabled.
|
||||
if (!FeatureFlags::GetInstance().GetFlags().enable_cancellation_flag) {
|
||||
@@ -80,13 +83,13 @@ bool CancellationFlag::Cancelled() const {
|
||||
}
|
||||
|
||||
void CancellationFlag::RegisterOnCancelListener(CancelListener *listener) {
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
|
||||
listeners_.emplace(listener);
|
||||
}
|
||||
|
||||
void CancellationFlag::UnregisterOnCancelListener(CancelListener *listener) {
|
||||
absl::MutexLock lock(*mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
|
||||
listeners_.erase(listener);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
@@ -74,7 +75,7 @@ class CancellationFlag {
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
int CancelListenersSize() const ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_.get());
|
||||
absl::MutexLock lock(*mutex_);
|
||||
return listeners_.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -126,13 +126,13 @@ class FeatureFlags {
|
||||
return *instance;
|
||||
}
|
||||
|
||||
const Flags& GetFlags() const ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::ReaderMutexLock lock(&mutex_);
|
||||
return flags_;
|
||||
static FeatureFlags& GetMutableInstanceForTesting() {
|
||||
return const_cast<FeatureFlags&>(GetInstance());
|
||||
}
|
||||
|
||||
static Flags& GetMutableFlagsForTesting() {
|
||||
return const_cast<FeatureFlags&>(GetInstance()).flags_;
|
||||
Flags GetFlags() const ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::ReaderMutexLock lock(mutex_);
|
||||
return flags_;
|
||||
}
|
||||
|
||||
// SetFlags for feature controlling
|
||||
|
||||
@@ -28,8 +28,8 @@ constexpr FeatureFlags::Flags kTestFeatureFlags{
|
||||
TEST(FeatureFlagsTest, CastUpdateWorks) {
|
||||
const FeatureFlags& features = FeatureFlags::GetInstance();
|
||||
EXPECT_TRUE(features.GetFlags().enable_async_bandwidth_upgrade);
|
||||
const_cast<FeatureFlags&>(FeatureFlags::GetInstance())
|
||||
.SetFlags({.enable_async_bandwidth_upgrade = false});
|
||||
FeatureFlags::GetMutableInstanceForTesting().SetFlags(
|
||||
{.enable_async_bandwidth_upgrade = false});
|
||||
|
||||
EXPECT_FALSE(features.GetFlags().enable_async_bandwidth_upgrade);
|
||||
}
|
||||
|
||||
@@ -1147,7 +1147,7 @@ void MediumEnvironment::UnregisterWifiHotspotMedium(
|
||||
}
|
||||
|
||||
void MediumEnvironment::SetFeatureFlags(const FeatureFlags::Flags& flags) {
|
||||
const_cast<FeatureFlags&>(FeatureFlags::GetInstance()).SetFlags(flags);
|
||||
FeatureFlags::GetMutableInstanceForTesting().SetFlags(flags);
|
||||
}
|
||||
|
||||
std::optional<FakeClock*> MediumEnvironment::GetSimulatedClock() {
|
||||
|
||||
Reference in New Issue
Block a user