File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments