Fix BLE commissioning deadlock caused by 0e41b19 (#23545)

diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp
index 9daa120..e29f04b 100644
--- a/src/platform/Linux/PlatformManagerImpl.cpp
+++ b/src/platform/Linux/PlatformManagerImpl.cpp
@@ -288,6 +288,14 @@
     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);
diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h
index bc5bc7c..2b1bad0 100644
--- a/src/platform/Linux/PlatformManagerImpl.h
+++ b/src/platform/Linux/PlatformManagerImpl.h
@@ -70,7 +70,7 @@
      * @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);
     }