Skip to content

Run btrMgr_IncomingConnectionAuthentication on separate thread in DeviceStatusCb#74

Draft
Copilot wants to merge 6 commits intodevelopfrom
copilot/run-incoming-connection-authentication-again
Draft

Run btrMgr_IncomingConnectionAuthentication on separate thread in DeviceStatusCb#74
Copilot wants to merge 6 commits intodevelopfrom
copilot/run-incoming-connection-authentication-again

Conversation

Copy link

Copilot AI commented Feb 20, 2026

btrMgr_IncomingConnectionAuthentication blocks the BTRCore callback thread for up to 20 seconds polling for UI response, preventing other Bluetooth device events from being processed during authentication.

Changes

Threading infrastructure:

  • stBTRMgrAuthThreadData: Holds device status and snapshotted global handles
  • btrMgr_IncomingConnectionAuthenticationThread: Thread entry point that runs authentication and handles result (disconnect on failure, post device found event on success)
  • btrMgr_SpawnAuthenticationThread: Helper function encapsulating thread spawn logic

Modified call sites (4):

  • BTRMGR_ConnectGamepads_StartUp - startup reconnection
  • btrMgr_DeviceStatusCb - AUTO_CONNECT_ENABLED, disconnected state, connecting state

Pattern:

// Before: blocks callback for 20s
int auth = 0;
btrMgr_IncomingConnectionAuthentication(p_StatusCB, &auth);
if (!auth) break;
// continue with device found event...

// After: returns immediately
if (!btrMgr_SpawnAuthenticationThread(p_StatusCB, deviceHandle, "context")) {
    break;
}
// thread handles authentication and event posting
break;

Thread Safety

Accesses same globals as original synchronous implementation (ghBTRCoreHdl, ghBTRMgrDevHdlLastDisconnected, gfpcBBTRMgrEventOut). Global handles are snapshotted at thread creation to minimize TOCTOU issues. No new race conditions introduced.

Uses GLib threading (g_thread_new/g_thread_unref) and memory allocation (g_malloc/g_free) consistent with existing patterns in codebase.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 5 commits February 20, 2026 06:13
…viceStatusCb

Co-authored-by: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com>
… thread safety

Co-authored-by: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com>
Co-authored-by: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com>
…cation complete

Co-authored-by: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate running btrMgr_IncomingConnectionAuthentication on a separate thread Run btrMgr_IncomingConnectionAuthentication on separate thread in DeviceStatusCb Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants