Skip to content

Commit

Permalink
[bluetooth] Boost priority while calling WSALookupService*()
Browse files Browse the repository at this point in the history
These functions may cause DLLs to be loaded for socket providers in the
process of enumerating device services. This macro temporarily boosts
this background thread's priority in order to avoid a priority inversion
where the main thread (and others) hang while this low priority thread
holds the dynamic library loader lock.

Observed this hang in crash/08cf98f7a1b73d12.

Bug: 973868
Change-Id: Ibb80c37c735471958f7b41460831aad2891ccf78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212671
Commit-Queue: Reilly Grant <[email protected]>
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <[email protected]>
Auto-Submit: Reilly Grant <[email protected]>
Reviewed-by: Ovidio de Jesús Ruiz-Henríquez <[email protected]>
Cr-Commit-Position: refs/heads/master@{#771181}
  • Loading branch information
reillyeon authored and Commit Bot committed May 21, 2020
1 parent f0cf956 commit 6bdf92d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions device/bluetooth/bluetooth_task_manager_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_thread_priority.h"
#include "device/bluetooth/bluetooth_classic_win.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_init_win.h"
Expand Down Expand Up @@ -644,6 +645,10 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
const GUID& protocol_uuid,
bool search_cached_services_only,
std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states) {
// Mitigate the issues caused by loading DLLs on a background thread
// (http://crbug/973868).
SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY();

// Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt.
WSAQUERYSET sdp_query;
ZeroMemory(&sdp_query, sizeof(sdp_query));
Expand Down

0 comments on commit 6bdf92d

Please sign in to comment.