From e815be36e76fd55a9e6cd18c6bdcbda3b63408b0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 2 Jul 2020 15:55:04 +0200 Subject: [PATCH] CordioHCILoop: properly terminate bleLoop thread Fixes https://github.com/arduino-libraries/ArduinoBLE/issues/65 --- src/utility/HCICordioTransport.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 1de5b4ce..15f0e128 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -162,7 +162,7 @@ static void bleLoop() } static rtos::EventFlags bleEventFlags; -static rtos::Thread bleLoopThread; +static rtos::Thread* bleLoopThread = NULL; HCICordioTransportClass::HCICordioTransportClass() : @@ -186,7 +186,10 @@ int HCICordioTransportClass::begin() CordioHCIHook::getDriver().initialize(); CordioHCIHook::getDriver().start_reset_sequence(); - bleLoopThread.start(bleLoop); + if (bleLoopThread == NULL) { + bleLoopThread = new rtos::Thread(); + bleLoopThread->start(bleLoop); + } CordioHCIHook::setDataReceivedHandler(HCICordioTransportClass::onDataReceived); @@ -197,7 +200,11 @@ int HCICordioTransportClass::begin() void HCICordioTransportClass::end() { - bleLoopThread.terminate(); + if (bleLoopThread != NULL) { + bleLoopThread->terminate(); + delete bleLoopThread; + bleLoopThread = NULL; + } CordioHCIHook::getDriver().terminate();