mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
committed by
GitHub
parent
acb64dff97
commit
d81ef2bc5c
@@ -21,7 +21,6 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
|
||||
|
||||
void MechanismLigament2d::UpdateEntries(
|
||||
std::shared_ptr<nt::NetworkTable> table) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
table->GetEntry(".type").SetString("line");
|
||||
|
||||
m_colorEntry = table->GetEntry("color");
|
||||
|
||||
@@ -20,14 +20,12 @@ void MechanismRoot2d::SetPosition(double x, double y) {
|
||||
}
|
||||
|
||||
void MechanismRoot2d::UpdateEntries(std::shared_ptr<nt::NetworkTable> table) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_xEntry = table->GetEntry("x");
|
||||
m_yEntry = table->GetEntry("y");
|
||||
Flush();
|
||||
}
|
||||
|
||||
inline void MechanismRoot2d::Flush() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_xEntry) {
|
||||
m_xEntry.SetDouble(m_x);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user