Skip to content

Commit

Permalink
gattlib_adapter_close: Do not block mutex while waiting for scan_loop…
Browse files Browse the repository at this point in the history
…_thread to complete
  • Loading branch information
oliviermartin committed Apr 10, 2024
1 parent 3f2e918 commit bc06c6d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dbus/gattlib_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,16 @@ int gattlib_adapter_close(gattlib_adapter_t* adapter) {
gattlib_adapter_scan_disable(adapter);

_wait_scan_loop_stop_scanning(adapter);

// We must release gattlib mutex to not block the library
// We must also increase reference counter to not wait for a thread that has been freed
GThread *scan_loop_thread = adapter->backend.ble_scan.scan_loop_thread;
g_thread_ref(scan_loop_thread);
g_rec_mutex_unlock(&m_gattlib_mutex);
g_thread_join(adapter->backend.ble_scan.scan_loop_thread);
// At this stage scan_loop_thread should have completed
g_rec_mutex_lock(&m_gattlib_mutex);
g_thread_unref(scan_loop_thread);
}

// Unref/Free the adapter
Expand Down

0 comments on commit bc06c6d

Please sign in to comment.