mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Implements locking in C++ DriverStation, and adds double buffering to DS Thread (#25)
Currently, about 5ms of every 20ms loop the DS thread would hold the mutex, while grabbing data. During this time, and call to grab joystick data would be blocked. This change grabs the joystick data to a cache, and then grabs the mutex and moves the data references around. This is much more efficient then the old code, and gives teams more of their teleop loop time back for use. Another major change this does is use preallocated arrays when entering the JNI. Previously every JNI DS call would allocate an entire new array. With a GC'd language where those arrays go on the heap, thats a problem, and creates tons of garbage. That garbage is no longer created anymore, as all arrays and byte buffers sent to JNI in the DS are preallocated. In addition, GetJoystickName was always returning joystick 0 data, which this fixes.
This commit is contained in:
committed by
Peter Johnson
parent
0965d60a71
commit
a4f0c4fbe0
@@ -142,37 +142,47 @@ Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_NativeH
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
|
||||
* Method: HALGetJoystickAxes
|
||||
* Signature: (B)[S
|
||||
* Signature: (B[S)B
|
||||
*/
|
||||
JNIEXPORT jshortArray JNICALL
|
||||
JNIEXPORT jbyte JNICALL
|
||||
Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickAxes(
|
||||
JNIEnv *env, jclass, jbyte joystickNum) {
|
||||
JNIEnv * env, jclass, jbyte joystickNum, jshortArray axesArray) {
|
||||
NETCOMM_LOG(logDEBUG) << "Calling HALJoystickAxes";
|
||||
HALJoystickAxes axes;
|
||||
HALGetJoystickAxes(joystickNum, &axes);
|
||||
|
||||
jshortArray axesArray = env->NewShortArray(axes.count);
|
||||
jsize javaSize = env->GetArrayLength(axesArray);
|
||||
if (axes.count > javaSize)
|
||||
{
|
||||
ThrowIllegalArgumentException(env, "Native array size larger then passed in java array size");
|
||||
}
|
||||
|
||||
env->SetShortArrayRegion(axesArray, 0, axes.count, axes.axes);
|
||||
|
||||
return axesArray;
|
||||
return axes.count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
|
||||
* Method: HALGetJoystickPOVs
|
||||
* Signature: (B)[S
|
||||
* Signature: (B[S)B
|
||||
*/
|
||||
JNIEXPORT jshortArray JNICALL
|
||||
JNIEXPORT jbyte JNICALL
|
||||
Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickPOVs(
|
||||
JNIEnv *env, jclass, jbyte joystickNum) {
|
||||
JNIEnv * env, jclass, jbyte joystickNum, jshortArray povsArray) {
|
||||
NETCOMM_LOG(logDEBUG) << "Calling HALJoystickPOVs";
|
||||
HALJoystickPOVs povs;
|
||||
HALGetJoystickPOVs(joystickNum, &povs);
|
||||
|
||||
jshortArray povsArray = env->NewShortArray(povs.count);
|
||||
jsize javaSize = env->GetArrayLength(povsArray);
|
||||
if (povs.count > javaSize)
|
||||
{
|
||||
ThrowIllegalArgumentException(env, "Native array size larger then passed in java array size");
|
||||
}
|
||||
|
||||
env->SetShortArrayRegion(povsArray, 0, povs.count, povs.povs);
|
||||
|
||||
return povsArray;
|
||||
return povs.count;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user