[wpilib] Fix deadlocks in Mechanism2d et al. (#3770)

UpdateEntries() and Flush() are called from methods that lock the mutex,
so locking it again will cause deadlocks. This also updates the Java
code to make MechanismObject2d::update synchronized like in the C++
version.
This commit is contained in:
Prateek Machiraju
2021-12-06 17:42:02 -05:00
committed by GitHub
parent acb64dff97
commit d81ef2bc5c
6 changed files with 8 additions and 7 deletions

View File

@@ -128,7 +128,7 @@ public class MechanismLigament2d extends MechanismObject2d {
}
@Override
protected synchronized void updateEntries(NetworkTable table) {
protected void updateEntries(NetworkTable table) {
table.getEntry(".type").setString("line");
m_angleEntry = table.getEntry("angle");
m_lengthEntry = table.getEntry("length");
@@ -138,7 +138,7 @@ public class MechanismLigament2d extends MechanismObject2d {
}
/** Flush latest data to NT. */
private synchronized void flush() {
private void flush() {
if (m_angleEntry != null) {
m_angleEntry.setDouble(m_angle);
}

View File

@@ -52,7 +52,7 @@ public abstract class MechanismObject2d {
return object;
}
final void update(NetworkTable table) {
final synchronized void update(NetworkTable table) {
m_table = table;
updateEntries(m_table);
for (MechanismObject2d obj : m_objects.values()) {

View File

@@ -86,7 +86,7 @@ public final class MechanismRoot2d {
return m_name;
}
private synchronized void flush() {
private void flush() {
if (m_xEntry != null) {
m_xEntry.setDouble(m_x);
}