diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index bc7f10f430e661..943b78e4a68323 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -18,6 +18,7 @@ import("//build_overrides/pigweed.gni") import("${build_root}/config/linux/pkg_config.gni") import("${chip_root}/build/chip/buildconfig_header.gni") +import("${chip_root}/src/system/system.gni") import("device.gni") @@ -526,6 +527,10 @@ if (chip_device_platform != "none") { "RuntimeOptionsProvider.cpp", ] + if (chip_system_config_locking != "none") { + sources += [ "PlatformLockSupport.cpp" ] + } + # Linux has its own NetworkCommissioningThreadDriver if (chip_enable_openthread && chip_device_platform != "linux" && chip_device_platform != "tizen" && chip_device_platform != "webos") { diff --git a/src/platform/PlatformEventSupport.cpp b/src/platform/PlatformEventSupport.cpp index 13929f992bff06..947a7f2fe691f8 100644 --- a/src/platform/PlatformEventSupport.cpp +++ b/src/platform/PlatformEventSupport.cpp @@ -44,17 +44,5 @@ CHIP_ERROR PlatformEventing::StartTimer(System::Layer & aLayer, System::Clock::T return PlatformMgr().StartChipTimer(delay); } -#if !CHIP_SYSTEM_CONFIG_NO_LOCKING -void PlatformEventing::LockMatterStack() -{ - PlatformMgr().LockChipStack(); -} - -void PlatformEventing::UnlockMatterStack() -{ - PlatformMgr().UnlockChipStack(); -} -#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING - } // namespace System } // namespace chip diff --git a/src/platform/PlatformLockSupport.cpp b/src/platform/PlatformLockSupport.cpp new file mode 100644 index 00000000000000..61a0d18af0c6a2 --- /dev/null +++ b/src/platform/PlatformLockSupport.cpp @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Nest Labs, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Provides implementations of the CHIP System Layer platform + * event functions that are suitable for use on all platforms. + */ +/* this file behaves like a config.h, comes first */ +#include +#include +#include + +namespace chip { +namespace System { + +using namespace ::chip::DeviceLayer; + +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING +void PlatformLocking::LockMatterStack() +{ + PlatformMgr().LockChipStack(); +} + +void PlatformLocking::UnlockMatterStack() +{ + PlatformMgr().UnlockChipStack(); +} +#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING + +} // namespace System +} // namespace chip diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn index 3fff2a61e648da..9b8096b52795bc 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -256,6 +256,10 @@ static_library("system") { ] } + if (chip_system_config_locking != "none") { + sources += [ "PlatformLockSupport.h" ] + } + cflags = [ "-Wconversion" ] public_deps = [ diff --git a/src/system/PlatformEventSupport.h b/src/system/PlatformEventSupport.h index 221feaee5348e1..9c0e85a545cd44 100644 --- a/src/system/PlatformEventSupport.h +++ b/src/system/PlatformEventSupport.h @@ -31,10 +31,6 @@ class PlatformEventing public: static CHIP_ERROR ScheduleLambdaBridge(System::Layer & aLayer, LambdaBridge && bridge); static CHIP_ERROR StartTimer(System::Layer & aLayer, System::Clock::Timeout aTimeout); -#if !CHIP_SYSTEM_CONFIG_NO_LOCKING - static void LockMatterStack(); - static void UnlockMatterStack(); -#endif }; } // namespace System diff --git a/src/system/PlatformLockSupport.h b/src/system/PlatformLockSupport.h new file mode 100644 index 00000000000000..ac4ad03e4b9d3c --- /dev/null +++ b/src/system/PlatformLockSupport.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace System { + +class Layer; +class Object; + +class PlatformLocking +{ +public: + static void LockMatterStack(); + static void UnlockMatterStack(); +}; + +} // namespace System +} // namespace chip diff --git a/src/system/SystemLayer.cpp b/src/system/SystemLayer.cpp index 067032efb7b5db..4cb411006f6e75 100644 --- a/src/system/SystemLayer.cpp +++ b/src/system/SystemLayer.cpp @@ -17,6 +17,9 @@ #include #include #include +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING +#include +#endif namespace chip { namespace System { @@ -35,9 +38,9 @@ CHIP_ERROR Layer::ScheduleLambdaBridge(LambdaBridge && bridge) CHIP_ERROR Layer::RunWithMatterContextLock(std::function nonBlockingFunc) { CHIP_ERROR err = CHIP_NO_ERROR; - PlatformEventing::LockMatterStack(); + PlatformLocking::LockMatterStack(); err = nonBlockingFunc(); - PlatformEventing::UnlockMatterStack(); + PlatformLocking::UnlockMatterStack(); return err; } #endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING