Skip to content

Commit aaab2dc

Browse files
committed
gattlib_adapter_close: Do not block mutex while waiting for scan_loop_thread to complete
1 parent 880f1d2 commit aaab2dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dbus/gattlib_adapter.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,18 @@ int gattlib_adapter_close(gattlib_adapter_t* adapter) {
690690
GATTLIB_LOG(GATTLIB_DEBUG, "Bluetooth adapter %s was scanning. We stop the scan", adapter->name);
691691
gattlib_adapter_scan_disable(adapter);
692692

693+
// We must release gattlib mutex to not block the library
694+
// We must also increase reference counter to not wait for a thread that has been freed
695+
GThread *scan_loop_thread = adapter->backend.ble_scan.scan_loop_thread;
696+
g_thread_ref(scan_loop_thread);
697+
g_rec_mutex_unlock(&m_gattlib_mutex);
698+
693699
_wait_scan_loop_stop_scanning(adapter);
700+
694701
g_thread_join(adapter->backend.ble_scan.scan_loop_thread);
702+
// At this stage scan_loop_thread should have completed
703+
g_rec_mutex_lock(&m_gattlib_mutex);
704+
g_thread_unref(scan_loop_thread);
695705
}
696706

697707
// Unref/Free the adapter

0 commit comments

Comments
 (0)