From 182ebad725f5356ec6c1a1fee5a26600d48e4f97 Mon Sep 17 00:00:00 2001 From: Nick Bourdakos Date: Tue, 9 May 2023 11:34:50 -0700 Subject: [PATCH] Use push and pop to add back the `CreateMutex` Windows macro to avoid issues in Windows app code. PiperOrigin-RevId: 530668276 --- internal/platform/implementation/platform.h | 9 +++++---- internal/platform/implementation/windows/platform.cc | 7 +++---- internal/platform/mutex.h | 5 +++++ internal/platform/pipe.cc | 5 +++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/internal/platform/implementation/platform.h b/internal/platform/implementation/platform.h index 6860d15f..4c494d38 100644 --- a/internal/platform/implementation/platform.h +++ b/internal/platform/implementation/platform.h @@ -56,10 +56,6 @@ #include "internal/platform/os_name.h" #include "internal/platform/payload_id.h" -#ifdef CreateMutex -#undef CreateMutex -#endif - namespace nearby { namespace api { @@ -103,7 +99,12 @@ class ImplementationPlatform { static std::unique_ptr CreateCountDownLatch( std::int32_t count); + +#pragma push_macro("CreateMutex") +#undef CreateMutex static std::unique_ptr CreateMutex(Mutex::Mode mode); +#pragma pop_macro("CreateMutex") + static std::unique_ptr CreateConditionVariable( Mutex* mutex); diff --git a/internal/platform/implementation/windows/platform.cc b/internal/platform/implementation/windows/platform.cc index b7956fe8..c214237e 100644 --- a/internal/platform/implementation/windows/platform.cc +++ b/internal/platform/implementation/windows/platform.cc @@ -66,10 +66,6 @@ #include "internal/platform/implementation/windows/wifi_lan.h" #include "internal/platform/logging.h" -#ifdef CreateMutex -#undef CreateMutex -#endif - namespace nearby { namespace api { @@ -183,9 +179,12 @@ std::unique_ptr ImplementationPlatform::CreateCountDownLatch( return absl::make_unique(count); } +#pragma push_macro("CreateMutex") +#undef CreateMutex std::unique_ptr ImplementationPlatform::CreateMutex(Mutex::Mode mode) { return absl::make_unique(mode); } +#pragma pop_macro("CreateMutex") std::unique_ptr ImplementationPlatform::CreateConditionVariable(Mutex* mutex) { diff --git a/internal/platform/mutex.h b/internal/platform/mutex.h index 1bf9d054..7c22764c 100644 --- a/internal/platform/mutex.h +++ b/internal/platform/mutex.h @@ -23,6 +23,9 @@ namespace nearby { +#pragma push_macro("CreateMutex") +#undef CreateMutex + // This is a classic mutex can be acquired at most once. // Atttempt to acuire mutex from the same thread that is holding it will likely // cause a deadlock. @@ -71,6 +74,8 @@ class ABSL_LOCKABLE RecursiveMutex final { std::unique_ptr impl_; }; +#pragma pop_macro("CreateMutex") + } // namespace nearby #endif // PLATFORM_PUBLIC_MUTEX_H_ diff --git a/internal/platform/pipe.cc b/internal/platform/pipe.cc index ad630d4e..25a0b9e9 100644 --- a/internal/platform/pipe.cc +++ b/internal/platform/pipe.cc @@ -24,10 +24,15 @@ namespace { using Platform = api::ImplementationPlatform; } +#pragma push_macro("CreateMutex") +#undef CreateMutex + Pipe::Pipe() { auto mutex = Platform::CreateMutex(api::Mutex::Mode::kRegular); auto cond = Platform::CreateConditionVariable(mutex.get()); Setup(std::move(mutex), std::move(cond)); } +#pragma pop_macro("CreateMutex") + } // namespace nearby