@@ -276,25 +276,23 @@ void GetTextEntries(unsigned short txtLen, uint8_t * txtRecord, std::vector<chip
276
276
}
277
277
}
278
278
279
- gboolean OnResolveFinalize (gpointer userData )
279
+ static void HandleResolveTask ( intptr_t context )
280
280
{
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)
284
284
{
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 ;
289
287
}
290
288
289
+ rCtx->Finalize (CHIP_NO_ERROR);
291
290
rCtx->mInstance ->RemoveContext (rCtx);
292
- return G_SOURCE_REMOVE;
293
291
}
294
292
295
293
void OnResolve (dnssd_error_e result, dnssd_service_h service, void * userData)
296
294
{
297
- ChipLogDetail (DeviceLayer, " DNSsd %s" , __func__);
295
+ ChipLogProgress (DeviceLayer, " DNSsd %s" , __func__);
298
296
299
297
auto rCtx = reinterpret_cast <chip::Dnssd::ResolveContext *>(userData);
300
298
@@ -357,17 +355,10 @@ void OnResolve(dnssd_error_e result, dnssd_service_h service, void * userData)
357
355
358
356
rCtx->mResult .mAddress .emplace (ipAddr);
359
357
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 ()));
371
362
372
363
return ;
373
364
@@ -487,6 +478,7 @@ ResolveContext::~ResolveContext()
487
478
488
479
void ResolveContext::Finalize (CHIP_ERROR error)
489
480
{
481
+ ChipLogProgress (DeviceLayer, " DNSsd %s" , __func__);
490
482
// In case of error, run the callback function with nullptr as the result.
491
483
VerifyOrReturn (error == CHIP_NO_ERROR, mCallback (mCbContext , nullptr , chip::Span<chip::Inet::IPAddress>(), error));
492
484
0 commit comments