Use push and pop to add back the CreateMutex Windows macro to avoid issues in Windows app code.

PiperOrigin-RevId: 530668276
This commit is contained in:
Nick Bourdakos
2023-05-09 11:36:06 -07:00
committed by Copybara-Service
parent ebab912fb6
commit 182ebad725
4 changed files with 18 additions and 8 deletions
+5 -4
View File
@@ -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<CountDownLatch> CreateCountDownLatch(
std::int32_t count);
#pragma push_macro("CreateMutex")
#undef CreateMutex
static std::unique_ptr<Mutex> CreateMutex(Mutex::Mode mode);
#pragma pop_macro("CreateMutex")
static std::unique_ptr<ConditionVariable> CreateConditionVariable(
Mutex* mutex);
@@ -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<CountDownLatch> ImplementationPlatform::CreateCountDownLatch(
return absl::make_unique<shared::CountDownLatch>(count);
}
#pragma push_macro("CreateMutex")
#undef CreateMutex
std::unique_ptr<Mutex> ImplementationPlatform::CreateMutex(Mutex::Mode mode) {
return absl::make_unique<windows::Mutex>(mode);
}
#pragma pop_macro("CreateMutex")
std::unique_ptr<ConditionVariable>
ImplementationPlatform::CreateConditionVariable(Mutex* mutex) {
+5
View File
@@ -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<api::Mutex> impl_;
};
#pragma pop_macro("CreateMutex")
} // namespace nearby
#endif // PLATFORM_PUBLIC_MUTEX_H_
+5
View File
@@ -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