diff --git a/src/inet/TCPEndPointImplLwIP.cpp b/src/inet/TCPEndPointImplLwIP.cpp index 0dc56d2dbfbdf6..9021dcfa350047 100644 --- a/src/inet/TCPEndPointImplLwIP.cpp +++ b/src/inet/TCPEndPointImplLwIP.cpp @@ -788,9 +788,9 @@ err_t TCPEndPointImplLwIP::LwIPHandleIncomingConnection(void * arg, struct tcp_p if (arg != nullptr) { - TCPEndPointImplLwIP * listenEP = static_cast(arg); - TCPEndPointImplLwIP * conEP = nullptr; - System::LayerFreeRTOS & lSystemLayer = static_cast(listenEP->GetSystemLayer()); + TCPEndPointImplLwIP * listenEP = static_cast(arg); + TCPEndPointImplLwIP * conEP = nullptr; + System::Layer & lSystemLayer = listenEP->GetSystemLayer(); // Tell LwIP we've accepted the connection so it can decrement the listen PCB's pending_accepts counter. tcp_accepted(listenEP->mTCP); @@ -805,8 +805,14 @@ err_t TCPEndPointImplLwIP::LwIPHandleIncomingConnection(void * arg, struct tcp_p if (err == CHIP_NO_ERROR) { TCPEndPoint * connectEndPoint = nullptr; - err = lSystemLayer.RunOnMatterContext( +#if CHIP_SYSTEM_CONFIG_NO_LOCKING + // TODO This should be in Matter context but we cannot use SystemLayer.ScheduleLambda() here as the allocated endpoint + // will be used in the following. + err = listenEP->GetEndPointManager().NewEndPoint(&connectEndPoint); +#else + err = lSystemLayer.RunWithMatterContextLock( [&listenEP, &connectEndPoint]() { return listenEP->GetEndPointManager().NewEndPoint(&connectEndPoint); }); +#endif conEP = static_cast(connectEndPoint); } @@ -954,8 +960,8 @@ void TCPEndPointImplLwIP::LwIPHandleError(void * arg, err_t lwipErr) { if (arg != nullptr) { - TCPEndPointImplLwIP * ep = static_cast(arg); - System::LayerFreeRTOS & lSystemLayer = static_cast(ep->GetSystemLayer()); + TCPEndPointImplLwIP * ep = static_cast(arg); + System::Layer & lSystemLayer = ep->GetSystemLayer(); // At this point LwIP has already freed the PCB. Since the thread that owns the TCPEndPoint may // try to use the PCB before it receives the TCPError event posted below, we set the PCB to NULL diff --git a/src/platform/PlatformEventSupport.cpp b/src/platform/PlatformEventSupport.cpp index cfa598db340642..13929f992bff06 100644 --- a/src/platform/PlatformEventSupport.cpp +++ b/src/platform/PlatformEventSupport.cpp @@ -44,17 +44,17 @@ CHIP_ERROR PlatformEventing::StartTimer(System::Layer & aLayer, System::Clock::T return PlatformMgr().StartChipTimer(delay); } -#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT -void PlatformEventing::LockMatterStack(System::Layer & aLayer) +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING +void PlatformEventing::LockMatterStack() { PlatformMgr().LockChipStack(); } -void PlatformEventing::UnlockMatterStack(System::Layer & aLayer) +void PlatformEventing::UnlockMatterStack() { PlatformMgr().UnlockChipStack(); } -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT +#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING } // namespace System } // namespace chip diff --git a/src/system/PlatformEventSupport.h b/src/system/PlatformEventSupport.h index 4fb7045d1b21e7..221feaee5348e1 100644 --- a/src/system/PlatformEventSupport.h +++ b/src/system/PlatformEventSupport.h @@ -31,9 +31,9 @@ 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_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT - static void LockMatterStack(System::Layer & aLayer); - static void UnlockMatterStack(System::Layer & aLayer); +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING + static void LockMatterStack(); + static void UnlockMatterStack(); #endif }; diff --git a/src/system/SystemLayer.cpp b/src/system/SystemLayer.cpp index 5d2c6a8fe0f80d..628fab6430341f 100644 --- a/src/system/SystemLayer.cpp +++ b/src/system/SystemLayer.cpp @@ -31,16 +31,16 @@ CHIP_ERROR Layer::ScheduleLambdaBridge(LambdaBridge && bridge) return lReturn; } -#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT -CHIP_ERROR LayerFreeRTOS::RunOnMatterContext(std::function func) +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING +CHIP_ERROR Layer::RunWithMatterContextLock(std::function func) { CHIP_ERROR err = CHIP_NO_ERROR; - PlatformEventing::LockMatterStack(*this); + PlatformEventing::LockMatterStack(); err = func(); - PlatformEventing::UnlockMatterStack(*this); + PlatformEventing::UnlockMatterStack(); return err; } -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT +#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING } // namespace System } // namespace chip diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h index b8112d9bd94edd..a381b011ea4c26 100644 --- a/src/system/SystemLayer.h +++ b/src/system/SystemLayer.h @@ -220,6 +220,10 @@ class DLL_EXPORT Layer return ScheduleLambdaBridge(std::move(bridge)); } +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING + CHIP_ERROR RunWithMatterContextLock(std::function); +#endif + private: CHIP_ERROR ScheduleLambdaBridge(LambdaBridge && bridge); @@ -232,8 +236,6 @@ class DLL_EXPORT Layer class LayerFreeRTOS : public Layer { -public: - CHIP_ERROR RunOnMatterContext(std::function); }; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP