aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-26 18:36:56 +0200
committerSven Gothel <[email protected]>2020-09-26 18:36:56 +0200
commit04251a6aaa72741eb29a8db61f3c12607b1e6f85 (patch)
tree84347e5ff98b353a62994e411dba63eade8167c9 /src/direct_bt
parent704ddf678544cd722aeae73b952a1899e5f319e8 (diff)
DBTAdapter, Device, HCIHandler: SEND (manual) EVENTs off-thread, mimic normal event delivered via HCIHandler's reader threadalt_sendevent
Diffstat (limited to 'src/direct_bt')
-rw-r--r--src/direct_bt/DBTAdapter.cpp8
-rw-r--r--src/direct_bt/DBTDevice.cpp11
-rw-r--r--src/direct_bt/HCIHandler.cpp6
3 files changed, 13 insertions, 12 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index 5e76c705..f210a4bd 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -561,10 +561,10 @@ exit:
if( discoveryTempDisabled || !res ) {
// In case of discoveryTempDisabled, power-off, le_enable_scane failure
// or already pulled HCIHandler, send the event directly.
- mgmtEvDeviceDiscoveringHCI(
- std::shared_ptr<MgmtEvent>(
- new MgmtEvtDiscovering(dev_id, ScanType::LE, false)
- ) );
+ // SEND_EVENT: Perform off-thread to avoid potential deadlock w/ application callbacks (similar when sent from HCIHandler's reader-thread)
+ std::thread bg(&DBTAdapter::mgmtEvDeviceDiscoveringHCI, this, std::shared_ptr<MgmtEvent>( new MgmtEvtDiscovering(dev_id, ScanType::LE, false) ) );
+ bg.detach();
+ // mgmtEvDeviceDiscoveringHCI( std::shared_ptr<MgmtEvent>( new MgmtEvtDiscovering(dev_id, ScanType::LE, false) ) );
}
DBG_PRINT("DBTAdapter::stopDiscovery: End: Result %d, keepAlive %d, currentScanType[native %s, meta %s], discoveryTempDisabled %d ...",
res, keepDiscoveringAlive.load(),
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index b1f1dccb..95af4dd8 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -426,8 +426,6 @@ void DBTDevice::disconnectGATT() noexcept {
}
HCIStatusCode DBTDevice::disconnect(const HCIStatusCode reason) noexcept {
- // ioErrorCause only true: pingGATT failure or GATTHandler::disconnect(..) called on failure
-
// Avoid disconnect re-entry -> potential deadlock
bool expConn = true; // C++11, exp as value since C++20
if( !allowDisconnect.compare_exchange_strong(expConn, false) ) {
@@ -480,10 +478,11 @@ exit:
// In case of an already pulled or disconnected HCIHandler (e.g. power-off)
// or in case the hci->disconnect() itself fails,
// send the DISCONN_COMPLETE event directly.
- adapter.mgmtEvDeviceDisconnectedHCI(
- std::shared_ptr<MgmtEvent>(
- new MgmtEvtDeviceDisconnected(adapter.dev_id, address, addressType, reason, hciConnHandle.load())
- ) );
+ // SEND_EVENT: Perform off-thread to avoid potential deadlock w/ application callbacks (similar when sent from HCIHandler's reader-thread)
+ std::thread bg(&DBTAdapter::mgmtEvDeviceDisconnectedHCI, &adapter, std::shared_ptr<MgmtEvent>(
+ new MgmtEvtDeviceDisconnected(adapter.dev_id, address, addressType, reason, hciConnHandle.load()) ) );
+ bg.detach();
+ // adapter.mgmtEvDeviceDisconnectedHCI( std::shared_ptr<MgmtEvent>( new MgmtEvtDeviceDisconnected(adapter.dev_id, address, addressType, reason, hciConnHandle.load()) ) );
}
WORDY_PRINT("DBTDevice::disconnect: End: status %s, handle 0x%X, isConnected %d/%d on %s",
getHCIStatusCodeString(res).c_str(), hciConnHandle.load(),
diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp
index 6affc1d3..6359ab83 100644
--- a/src/direct_bt/HCIHandler.cpp
+++ b/src/direct_bt/HCIHandler.cpp
@@ -606,8 +606,10 @@ HCIStatusCode HCIHandler::le_enable_scan(const bool enable, const bool filter_du
std::shared_ptr<HCIEvent> ev = processCommandComplete(req0, &ev_status, &status);
if( HCIStatusCode::SUCCESS == status ) {
- MgmtEvtDiscovering *e = new MgmtEvtDiscovering(dev_id, ScanType::LE, enable);
- sendMgmtEvent(std::shared_ptr<MgmtEvent>(e));
+ // SEND_EVENT: Perform off-thread to avoid potential deadlock w/ application callbacks (similar when sent from HCIHandler's reader-thread)
+ std::thread bg(&HCIHandler::sendMgmtEvent, this, std::shared_ptr<MgmtEvent>( new MgmtEvtDiscovering(dev_id, ScanType::LE, enable) ) );
+ bg.detach();
+ // sendMgmtEvent(std::shared_ptr<MgmtEvent>( new MgmtEvtDiscovering(dev_id, ScanType::LE, enable) ) );
}
return status;
}