Skip to content

Commit 7930620

Browse files
committed
Check to lock before calling context invoke sync function
1 parent 44bd675 commit 7930620

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/platform/Tizen/DnssdImpl.cpp

+4-27
Original file line numberDiff line numberDiff line change
@@ -276,42 +276,19 @@ void GetTextEntries(unsigned short txtLen, uint8_t * txtRecord, std::vector<chip
276276
}
277277
}
278278

279-
static void HandleResolveTask(intptr_t context)
279+
gboolean OnResolveFinalize(gpointer userData)
280280
{
281281
ChipLogDetail(DeviceLayer, "DNSsd %s", __func__);
282-
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(context);
283-
if (!rCtx)
284-
{
285-
ChipLogError(DeviceLayer, "Null context in HandleResolveTask");
286-
return;
287-
}
282+
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(userData);
288283

289284
{
285+
// Lock the stack mutex when calling the callback function, so that the callback
286+
// function could safely perform message exchange (e.g. PASE session pairing).
290287
chip::DeviceLayer::StackLock lock;
291288
rCtx->Finalize(CHIP_NO_ERROR);
292289
}
293290

294291
rCtx->mInstance->RemoveContext(rCtx);
295-
}
296-
297-
gboolean OnResolveFinalize(gpointer userData)
298-
{
299-
ChipLogDetail(DeviceLayer, "DNSsd %s", __func__);
300-
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(userData);
301-
if (!rCtx)
302-
{
303-
ChipLogError(DeviceLayer, "Null context in OnResolveFinalize");
304-
return G_SOURCE_REMOVE;
305-
}
306-
307-
CHIP_ERROR err = chip::DeviceLayer::PlatformMgr().ScheduleWork(HandleResolveTask, reinterpret_cast<intptr_t>(rCtx));
308-
if (err != CHIP_NO_ERROR)
309-
{
310-
ChipLogError(DeviceLayer, "Failed to schedule resolve task: %s", err.AsString());
311-
rCtx->mInstance->RemoveContext(rCtx);
312-
return G_SOURCE_REMOVE;
313-
}
314-
315292
return G_SOURCE_REMOVE;
316293
}
317294

src/platform/Tizen/PlatformManagerImpl.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,19 @@ void PlatformManagerImpl::_GLibMatterContextInvokeSync(LambdaBridge && bridge)
162162
},
163163
&invokeData, nullptr);
164164

165+
bool isChipStackLocked = PlatformMgr().IsChipStackLockedByCurrentThread() &&
166+
(mState.load(std::memory_order_relaxed) == State::kRunning);
167+
if (isChipStackLocked)
168+
{
169+
PlatformMgr().UnlockChipStack();
170+
}
171+
165172
std::unique_lock<std::mutex> lock(invokeData.mDoneMutex);
166173
invokeData.mDoneCond.wait(lock, [&invokeData]() { return invokeData.mDone; });
174+
if (isChipStackLocked)
175+
{
176+
PlatformMgr().LockChipStack();
177+
}
167178
}
168179

169180
} // namespace DeviceLayer

src/platform/Tizen/PlatformManagerImpl.h

-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
8888
CHIP_ERROR _InitChipStack();
8989
void _Shutdown();
9090

91-
#if CHIP_STACK_LOCK_TRACKING_ENABLED
92-
bool _IsChipStackLockedByCurrentThread() const { return true; };
93-
#endif
94-
9591
// ===== Members for internal use by the following friends.
9692

9793
friend PlatformManager & PlatformMgr();

0 commit comments

Comments
 (0)