Skip to content

Commit e7ef0b7

Browse files
committed
BLE: protect event signaling flag from concurent accesses.
1 parent c23911e commit e7ef0b7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

features/FEATURE_BLE/source/BLE.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stdio.h>
1818
#include "ble/BLE.h"
1919
#include "ble/BLEInstanceBase.h"
20+
#include "platform/mbed_critical.h"
2021

2122
#if defined(TARGET_OTA_ENABLED)
2223
#include "ble/services/DFUService.h"
@@ -299,16 +300,19 @@ void BLE::waitForEvent(void)
299300

300301
void BLE::processEvents()
301302
{
303+
core_util_critical_section_enter();
302304
if (event_signaled == false) {
305+
core_util_critical_section_exit();
303306
return;
304307
}
305308

309+
event_signaled = false;
310+
core_util_critical_section_exit();
311+
306312
if (!transport) {
307313
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_BACKEND_NOT_INITIALIZED), "bad handle to underlying transport");
308314
}
309315

310-
event_signaled = false;
311-
312316
transport->processEvents();
313317
}
314318

@@ -328,11 +332,14 @@ void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback)
328332

329333
void BLE::signalEventsToProcess()
330334
{
335+
core_util_critical_section_enter();
331336
if (event_signaled == true) {
337+
core_util_critical_section_exit();
332338
return;
333339
}
334340

335341
event_signaled = true;
342+
core_util_critical_section_exit();
336343

337344
if (whenEventsToProcess) {
338345
OnEventsToProcessCallbackContext params = {

0 commit comments

Comments
 (0)