Skip to content

Commit f6052ec

Browse files
strongly-typedsalkinium
authored andcommitted
[platform] CANUSB: add missing mutex usage
I was not able to receive messages from a CAN2USB. The mutex was already added but newer used.
1 parent 4d5cb7b commit f6052ec

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/modm/platform/can/canusb/canusb.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class CanUsb : public ::modm::Can
5353
inline bool
5454
isMessageAvailable()
5555
{
56-
return (!this->readBuffer.empty());
56+
MutexGuard stateGuard(readBufferLock);
57+
return (not this->readBuffer.empty());
5758
}
5859

5960
bool

src/modm/platform/can/canusb/canusb_impl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ template <typename SerialPort>
180180
bool
181181
modm::platform::CanUsb<SerialPort>::getMessage(can::Message& message)
182182
{
183+
MutexGuard stateGuard(readBufferLock);
183184
if (not this->readBuffer.empty())
184185
{
185186
message = this->readBuffer.front();
@@ -229,6 +230,7 @@ modm::platform::CanUsb<SerialPort>::update()
229230
if (modm::CanLawicelFormatter::convertToCanMessage(
230231
this->tmpRead.c_str(), message))
231232
{
233+
MutexGuard stateGuard(readBufferLock);
232234
this->readBuffer.push(message);
233235
}
234236
}

0 commit comments

Comments
 (0)