Skip to content

Commit

Permalink
Add PlatformLockSupport for system layer
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed Jan 13, 2025
1 parent 58b91ab commit 7f513d6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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") {
Expand Down
12 changes: 0 additions & 12 deletions src/platform/PlatformEventSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions src/platform/PlatformLockSupport.cpp
Original file line number Diff line number Diff line change
@@ -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 <platform/internal/CHIPDeviceLayerInternal.h>
#include <system/PlatformLockSupport.h>
#include <platform/PlatformManager.h>

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
4 changes: 4 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ static_library("system") {
]
}

if (chip_system_config_locking != "none") {
sources += [ "PlatformLockSupport.h" ]
}

cflags = [ "-Wconversion" ]

public_deps = [
Expand Down
4 changes: 0 additions & 4 deletions src/system/PlatformEventSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/system/PlatformLockSupport.h
Original file line number Diff line number Diff line change
@@ -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 <lib/core/CHIPError.h>
#include <system/SystemLayer.h>

namespace chip {
namespace System {

class Layer;
class Object;

class PlatformLocking
{
public:
static void LockMatterStack();
static void UnlockMatterStack();
};

} // namespace System
} // namespace chip
7 changes: 5 additions & 2 deletions src/system/SystemLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <lib/support/CodeUtils.h>
#include <system/PlatformEventSupport.h>
#include <system/SystemLayer.h>
#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
#include <system/PlatformLockSupport.h>
#endif

namespace chip {
namespace System {
Expand All @@ -35,9 +38,9 @@ CHIP_ERROR Layer::ScheduleLambdaBridge(LambdaBridge && bridge)
CHIP_ERROR Layer::RunWithMatterContextLock(std::function<CHIP_ERROR()> 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
Expand Down

0 comments on commit 7f513d6

Please sign in to comment.