serial thread name hack

This commit is contained in:
rusefi 2020-07-25 16:34:50 -04:00
parent 52caab3989
commit 47e1302827
1 changed files with 7 additions and 0 deletions

View File

@ -39,6 +39,8 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
@Override
public void setInputListener(DataListener listener) {
sp.addDataListener(new SerialPortDataListener() {
private boolean isFirstEvent = true;
@Override
public int getListeningEvents() {
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
@ -48,6 +50,11 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
return;
if (isFirstEvent) {
// a hack to have explicit thread name, see https://github.com/Fazecast/jSerialComm/issues/308
Thread.currentThread().setName("Serial Port Event Thread");
isFirstEvent = false;
}
int bytesAvailable = sp.bytesAvailable();
if (bytesAvailable <= 0)
return; // sometimes negative value is returned at least on Mac