From 0c1a1ea3baeda93c2d7b3b3b249d8ea72d150819 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 1 Aug 2023 10:58:35 -0400 Subject: [PATCH] Fix typo and restyle --- src/controller/python/BUILD.gn | 5 +++-- .../chip/native/ChipMainLoopWork_StackLock.cpp | 9 +++++---- .../chip/native/ChipMainLoopWork_WorkSchedule.cpp | 13 +++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/controller/python/BUILD.gn b/src/controller/python/BUILD.gn index edac2d776358d1..289009cca0aef0 100644 --- a/src/controller/python/BUILD.gn +++ b/src/controller/python/BUILD.gn @@ -33,7 +33,8 @@ config("controller_wno_deprecate") { declare_args() { chip_python_version = "0.0" chip_python_package_prefix = "chip" - chip_python_supports_stack_locking = (current_os != "mac") || (current_os != "ios") + chip_python_supports_stack_locking = + current_os != "mac" && current_os != "ios" } shared_library("ChipDeviceCtrl") { @@ -78,8 +79,8 @@ shared_library("ChipDeviceCtrl") { "chip/internal/ChipThreadWork.h", "chip/internal/CommissionerImpl.cpp", "chip/logging/LoggingRedirect.cpp", - "chip/native/PyChipError.cpp", "chip/native/ChipMainLoopWork.h", + "chip/native/PyChipError.cpp", "chip/tracing/TracingSetup.cpp", "chip/utils/DeviceProxyUtils.cpp", ] diff --git a/src/controller/python/chip/native/ChipMainLoopWork_StackLock.cpp b/src/controller/python/chip/native/ChipMainLoopWork_StackLock.cpp index 843f3e7a555a6c..c13580a3e0ac58 100644 --- a/src/controller/python/chip/native/ChipMainLoopWork_StackLock.cpp +++ b/src/controller/python/chip/native/ChipMainLoopWork_StackLock.cpp @@ -17,7 +17,7 @@ */ #include "ChipMainLoopWork.h" -#include +#include namespace chip { namespace MainLoopWork { @@ -27,14 +27,15 @@ using chip::DeviceLayer::PlatformMgr; class ScopedStackLock { - public: +public: ScopedStackLock() { PlatformMgr().LockChipStack(); } ~ScopedStackLock() { PlatformMgr().UnlockChipStack(); } }; -} // namespace +} // namespace -void ExecuteInMainLoop(std::function f) { +void ExecuteInMainLoop(std::function f) +{ ScopedStackLock lock; f(); } diff --git a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp index 61f3b94b75b98a..a42c9fde3233bd 100644 --- a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp +++ b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp @@ -43,26 +43,27 @@ void PerformWork(intptr_t arg) work->Post(); } +} // namespace -} // namespace - -void ExecuteInMainLoop(std::function f) { +void ExecuteInMainLoop(std::function f) +{ #if CHIP_STACK_LOCK_TRACKING_ENABLED - if (chip::DeviceLayer::PlatformMgr().IsChipStackLockedByCurrentThread()) { + if (chip::DeviceLayer::PlatformMgr().IsChipStackLockedByCurrentThread()) + { f(); return; } #endif #if defined(__APPLE__) - if (chip::DeviceLayer::PlatformManagerImpl()::IsWorkQueueCurrentQueue()) { + if (chip::DeviceLayer::PlatformManagerImpl()::IsWorkQueueCurrentQueue()) + { f(); return; } #endif - // NOTE: the code below assumes that chip main loop is running. // if it does not, this will deadlock. //