Skip to content

Commit d2695bb

Browse files
committed
HAL_SITL: fixed multi-thread race in CAN send
1 parent 340f43c commit d2695bb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libraries/AP_HAL_SITL/CANSocketIface.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ void CANIface::_pollWrite()
140140
}
141141
while (_hasReadyTx()) {
142142
WITH_SEMAPHORE(sem);
143-
const CanTxItem tx = *_tx_queue[0];
143+
const CanTxItem *tx = _tx_queue[0];
144+
if (tx == nullptr) {
145+
break;
146+
}
144147
const uint64_t curr_time = AP_HAL::micros64();
145-
if (tx.deadline >= curr_time) {
146-
// hal.console->printf("%x TDEAD: %lu CURRT: %lu DEL: %lu\n",tx.frame.id, tx.deadline, curr_time, tx.deadline-curr_time);
147-
bool ok = transport->send(tx.frame);
148+
if (tx->deadline >= curr_time) {
149+
bool ok = transport->send(tx->frame);
148150
if (ok) {
149151
stats.tx_success++;
150152
stats.last_transmit_us = curr_time;

0 commit comments

Comments
 (0)