Skip to content

Commit

Permalink
use closure
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed Jan 15, 2025
1 parent cbf1123 commit 220cf3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 50 deletions.
14 changes: 0 additions & 14 deletions src/system/SystemLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#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 @@ -34,16 +31,5 @@ CHIP_ERROR Layer::ScheduleLambdaBridge(LambdaBridge && bridge)
return lReturn;
}

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
CHIP_ERROR Layer::RunWithMatterContextLock(std::function<CHIP_ERROR()> nonBlockingFunc)
{
CHIP_ERROR err = CHIP_NO_ERROR;
PlatformLocking::LockMatterStack();
err = nonBlockingFunc();
PlatformLocking::UnlockMatterStack();
return err;
}
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

} // namespace System
} // namespace chip
17 changes: 15 additions & 2 deletions src/system/SystemLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include <ev.h>
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
#include <system/PlatformLockSupport.h>
#endif

namespace chip {
namespace System {

Expand Down Expand Up @@ -227,11 +231,20 @@ class DLL_EXPORT Layer
*
* CRITICAL: The function should be non-blocking to avoid dead lock.
*
* @param[in] nonBlockingFunc The non-blocking function to be called with Matter stack lock held.
* @param[in] nonBlockingFunc The non-blocking lambda to be called with Matter stack lock held.
*
* @retval The return value of the non-blocking function
*/
CHIP_ERROR RunWithMatterContextLock(std::function<CHIP_ERROR()> nonBlockingFunc);
template <typename Lambda>
CHIP_ERROR RunWithMatterContextLock(const Lambda & nonBlockingFunc)
{
static_assert(std::is_invocable_v<Lambda>, "lambda argument must be an invocable with no arguments");
CHIP_ERROR err = CHIP_NO_ERROR;
PlatformLocking::LockMatterStack();
err = nonBlockingFunc();
PlatformLocking::UnlockMatterStack();
return err;
}
#endif

private:
Expand Down
34 changes: 0 additions & 34 deletions src/system/SystemLayerLock.cpp

This file was deleted.

0 comments on commit 220cf3b

Please sign in to comment.