Fix main thread ID being potentially incorrect for simulation (#1923)

This commit is contained in:
Thad House
2019-10-07 20:45:33 -07:00
committed by Peter Johnson
parent 56d782b16c
commit 45b766a5dc

View File

@@ -38,7 +38,7 @@ public abstract class RobotBase implements AutoCloseable {
* The ID of the main Java thread.
*/
// This is usually 1, but it is best to make sure
public static final long MAIN_THREAD_ID = Thread.currentThread().getId();
private static long m_threadId = -1;
private static void setupCameraServerShared() {
CameraServerShared shared = new CameraServerShared() {
@@ -65,7 +65,7 @@ public abstract class RobotBase implements AutoCloseable {
@Override
public Long getRobotMainThreadId() {
return MAIN_THREAD_ID;
return RobotBase.getMainThreadId();
}
@Override
@@ -90,6 +90,7 @@ public abstract class RobotBase implements AutoCloseable {
*/
protected RobotBase() {
NetworkTableInstance inst = NetworkTableInstance.getDefault();
m_threadId = Thread.currentThread().getId();
setupCameraServerShared();
inst.setNetworkIdentity("Robot");
inst.startServer("/home/lvuser/networktables.ini");
@@ -100,6 +101,10 @@ public abstract class RobotBase implements AutoCloseable {
Shuffleboard.disableActuatorWidgets();
}
public static long getMainThreadId() {
return m_threadId;
}
@Deprecated
public void free() {
}