Make Java AnalogGyro.getAngle() thread-safe.

In the Java implementation, "result" is an instance variable (to avoid
needing to perform a memory allocation on each call to getAngle).  However,
this means that calls to getAngle() from multiple threads can step on each
other.  Synchronize the method to avoid this issue.

Reported by: Jackson Gray (http://www.chiefdelphi.com/forums/showthread.php?threadid=145124)

Note this does not synchronize accesses between configuration methods such
as calibrate() and accessor methods such as getAngle().

Change-Id: I9ecc962d4fba66f6134fd801cfd607f155b41fe5
This commit is contained in:
Peter Johnson
2016-03-03 23:37:45 -08:00
committed by Peter Johnson (294)
parent ec13d00b18
commit fa8b68419f

View File

@@ -165,7 +165,7 @@ public class AnalogGyro extends GyroBase implements Gyro, PIDSource, LiveWindowS
/**
* {@inheritDoc}
*/
public double getAngle() {
public synchronized double getAngle() {
if (m_analog == null) {
return 0.0;
} else {