Skip to content

Commit

Permalink
Fix BLE commissioning deadlock caused by 0e41b19 (#23545)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq authored and pull[bot] committed Jul 5, 2024
1 parent fd165a7 commit 1228398
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ CHIP_ERROR PlatformManagerImpl::RunOnGLibMainLoopThread(GSourceFunc callback, vo
VerifyOrReturnError(context != nullptr,
(ChipLogDetail(DeviceLayer, "Failed to get GLib main loop context"), CHIP_ERROR_INTERNAL));

// If we've been called from the GLib main loop thread itself, there is no reason to wait
// for the callback, as it will be executed immediately by the g_main_context_invoke() call
// below. Using a callback indirection in this case would cause a deadlock.
if (g_main_context_is_owner(context))
{
wait = false;
}

if (wait)
{
std::unique_lock<std::mutex> lock(mGLibMainLoopCallbackIndirectionMutex);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
* @brief Convenience method to require less casts to void pointers.
*/
template <class T>
CHIP_ERROR ScheduleOnGLibMainLoopThread(int (*callback)(T *), T * userData, bool wait = false)
CHIP_ERROR ScheduleOnGLibMainLoopThread(gboolean (*callback)(T *), T * userData, bool wait = false)
{
return RunOnGLibMainLoopThread(G_SOURCE_FUNC(callback), userData, wait);
}
Expand Down

0 comments on commit 1228398

Please sign in to comment.