New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinkInterface/Vehicle uses mutexes to synchronize writing bytes #8835
Conversation
…o the link instead of queued signals
src/Vehicle/Vehicle.cc
Outdated
|
||
return true; | ||
} | ||
QMutexLocker lock(&_sendMessageOnLinkMutex); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this lock needed given that link->writeBytesThreadSafe()
has its own lock? What is it protecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sure this stuff is thread safe as well:
if (!link->isConnected()) {
return false;
}
// Give the plugin a chance to adjust
_firmwarePlugin->adjustOutgoingMavlinkMessage(this, link, &message);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the joystick send will come through this path from another thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link->isConnected()
probably isn't too problematic. But this _firmwarePlugin->adjustOutgoingMavlinkMessage
is since it maintains a mavlink channel status if I remember correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, It doesn't look like it is needed. The adjustOutgoingMavlinkMessage()
function is 99.9% void. The only time something actually is done is for this:
case MAVLINK_MSG_ID_PARAM_SET:
_handleOutgoingParamSet(vehicle, outgoingLink, message);
Might as well put a mutex in there rather than annoying the other 99.9% of the time this never used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's a firmwareplugin override so you have no idea what can happen in there in a custom build. Without a change to the FirmwarePlugin method to mark as threadsafe required and likely a name change to prevent old unthreadsafe code from leaking through it needed. I can certainly do that. Seems like a better way to go intstead of the upper layers doing things which won't be needed most of the time.
Also there is gimbal control signal which when that gets fully implemented should switch to using this path as well. |
I should have also mentioned that this pull removes all the advanced joystick modes. Only joystick usage for RC is now supported. |
Crap, closed by accident. |
@dogmaphobic All good now? |
Yup! :) |
@DonLakeFlyer, @dogmaphobic this one leads to #9751 |
Previously writing bytes out to a link went through a sequence of multiple queued messages in Vehicle and LinkInterface to prevent thread safety issues. The problem is that doing it that way is dog slow. So slow that in cases where a joystick was being used on a device with a very slow CPU the MANUAL_CONTROL messages didn't make it through to the vehicle at a high enough frequency. It also chew more CPU than needed.
What happens now is that both Vehicle and LinkInterface use mutexes for thread safety in the following calls which are threadsafe:
The end result is Mavlink message sending QGC->Vehicle which is measured in nanoseconds instead of 100s of milliseconds. And also when using a joystick a significant reduction in CPU usage.