Skip to content

Commit a04ae1f

Browse files
authored
begin(baudrate,config) needs to be locked against multi-threaded access from the very start.! (#14)
1 parent 8861451 commit a04ae1f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/serial/SerialDispatcher.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void SerialDispatcher::begin(unsigned long baudrate)
4949

5050
void SerialDispatcher::begin(unsigned long baudrate, uint16_t config)
5151
{
52+
mbed::ScopedLock<rtos::Mutex> lock(_mutex);
53+
5254
if (!_is_initialized)
5355
{
5456
_serial.begin(baudrate, config);
@@ -57,8 +59,6 @@ void SerialDispatcher::begin(unsigned long baudrate, uint16_t config)
5759
while (!_has_tread_started) { }
5860
}
5961

60-
mbed::ScopedLock<rtos::Mutex> lock(_mutex);
61-
6262
/* Check if the thread calling begin is already in the list. */
6363
osThreadId_t const current_thread_id = rtos::ThisThread::get_id();
6464
if (findThreadCustomerDataById(rtos::ThisThread::get_id()) == std::end(_thread_customer_list))

0 commit comments

Comments
 (0)