Skip to content

Commit 8101227

Browse files
committed
Replace gsource idle with scheduleWork
1 parent 5e76f11 commit 8101227

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

src/platform/Tizen/DnssdImpl.cpp

+13-21
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,23 @@ void GetTextEntries(unsigned short txtLen, uint8_t * txtRecord, std::vector<chip
276276
}
277277
}
278278

279-
gboolean OnResolveFinalize(gpointer userData)
279+
static void HandleResolveTask(intptr_t context)
280280
{
281-
ChipLogDetail(DeviceLayer, "DNSsd %s", __func__);
282-
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(userData);
283-
281+
ChipLogProgress(DeviceLayer, "DNSsd %s", __func__);
282+
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(context);
283+
if (!rCtx)
284284
{
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).
287-
chip::DeviceLayer::StackLock lock;
288-
rCtx->Finalize(CHIP_NO_ERROR);
285+
ChipLogError(DeviceLayer, "Null context in HandleResolveTask");
286+
return;
289287
}
290288

289+
rCtx->Finalize(CHIP_NO_ERROR);
291290
rCtx->mInstance->RemoveContext(rCtx);
292-
return G_SOURCE_REMOVE;
293291
}
294292

295293
void OnResolve(dnssd_error_e result, dnssd_service_h service, void * userData)
296294
{
297-
ChipLogDetail(DeviceLayer, "DNSsd %s", __func__);
295+
ChipLogProgress(DeviceLayer, "DNSsd %s", __func__);
298296

299297
auto rCtx = reinterpret_cast<chip::Dnssd::ResolveContext *>(userData);
300298

@@ -357,17 +355,10 @@ void OnResolve(dnssd_error_e result, dnssd_service_h service, void * userData)
357355

358356
rCtx->mResult.mAddress.emplace(ipAddr);
359357

360-
{
361-
// Before calling the Resolve() callback, we need to lock stack mutex.
362-
// However, we cannot lock the stack mutex from here, because we might
363-
// face lock inversion problem. This callback (OnResolve()) is called
364-
// with the NSD internal mutex locked, which is also locked by the
365-
// dnssd_create_remote_service() function called in the Resolve(), and
366-
// the Resolve() itself is called with the stack mutex locked.
367-
chip::GAutoPtr<GSource> sourceIdle(g_idle_source_new());
368-
g_source_set_callback(sourceIdle.get(), OnResolveFinalize, rCtx, NULL);
369-
g_source_attach(sourceIdle.get(), g_main_context_get_thread_default());
370-
}
358+
err = chip::DeviceLayer::PlatformMgr().ScheduleWork(HandleResolveTask, reinterpret_cast<intptr_t>(rCtx));
359+
VerifyOrExit(
360+
err == CHIP_NO_ERROR,
361+
ChipLogError(DeviceLayer, "Failed to schedule resolve task: %s", err.AsString()));
371362

372363
return;
373364

@@ -487,6 +478,7 @@ ResolveContext::~ResolveContext()
487478

488479
void ResolveContext::Finalize(CHIP_ERROR error)
489480
{
481+
ChipLogProgress(DeviceLayer, "DNSsd %s", __func__);
490482
// In case of error, run the callback function with nullptr as the result.
491483
VerifyOrReturn(error == CHIP_NO_ERROR, mCallback(mCbContext, nullptr, chip::Span<chip::Inet::IPAddress>(), error));
492484

src/platform/Tizen/PlatformManagerImpl.cpp

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

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

180169
} // namespace DeviceLayer

0 commit comments

Comments
 (0)