mavlink / rust-mavlink

MAVLink library for Rust.
https://mavlink.github.io/rust-mavlink/mavlink/
Apache License 2.0
158 stars 79 forks source link

(Question) SerialConnection mutex locks read and write methods #195

Open antonio-sc66 opened 1 year ago

antonio-sc66 commented 1 year ago

Hi,

To my understanding, the SerialConnection has a single mutex to lock the port attribute, this means that if a SerialConnection is shared between threads using Arc (like in the mavlink-dump binary) it won't be posible to perform a recv call in one thread and a send call in another thread at the same time. If no messages are received it will never be able to send (mutex will be locked until recv ends).

SerialPorts can send and receive at the same time, but the crate used doesn't split the tx and rx channels, I guess this is why a single Port and mutex is being used.

How can a workaround be implemented?

Would it be posible to have an auxiliary mutex to split reading and writing locks? Methods performing read operations would lock an specific mutex and methods performing write operations would lock the other mutex. It's not elegant but the port is hidden inside the structure. Would this make any sense?

patrickelectric commented 1 year ago

That was in theory fixed by this PR https://github.com/mavlink/rust-mavlink/pull/102

But, I have not rebased it or tested in embedded devices to be sure that works.