Synchronize open/close on class as well as instance
This commit is contained in:
parent
bcc9e1e19f
commit
b52271c48c
|
@ -7,7 +7,7 @@ buildscript {
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
id 'biz.aQute.bnd.builder' version '5.0.0'
|
id 'biz.aQute.bnd.builder' version '6.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.fazecast'
|
group = 'com.fazecast'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* SerialPort.java
|
* SerialPort.java
|
||||||
*
|
*
|
||||||
* Created on: Feb 25, 2012
|
* Created on: Feb 25, 2012
|
||||||
* Last Updated on: Nov 12, 2021
|
* Last Updated on: Nov 19, 2021
|
||||||
* Author: Will Hedgecock
|
* Author: Will Hedgecock
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2021 Fazecast, Inc.
|
* Copyright (C) 2012-2021 Fazecast, Inc.
|
||||||
|
@ -417,6 +417,9 @@ public final class SerialPort
|
||||||
* @return Whether the port was successfully opened with a valid configuration.
|
* @return Whether the port was successfully opened with a valid configuration.
|
||||||
*/
|
*/
|
||||||
public final synchronized boolean openPort(int safetySleepTime, int deviceSendQueueSize, int deviceReceiveQueueSize)
|
public final synchronized boolean openPort(int safetySleepTime, int deviceSendQueueSize, int deviceReceiveQueueSize)
|
||||||
|
{
|
||||||
|
// Synchronize this method to the class scope as well
|
||||||
|
synchronized (SerialPort.class)
|
||||||
{
|
{
|
||||||
// Set the send/receive internal buffer sizes, and return true if already opened
|
// Set the send/receive internal buffer sizes, and return true if already opened
|
||||||
safetySleepTimeMS = safetySleepTime;
|
safetySleepTimeMS = safetySleepTime;
|
||||||
|
@ -469,6 +472,7 @@ public final class SerialPort
|
||||||
}
|
}
|
||||||
return (portHandle > 0);
|
return (portHandle > 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens this serial port for reading and writing with an optional delay time.
|
* Opens this serial port for reading and writing with an optional delay time.
|
||||||
|
@ -503,6 +507,9 @@ public final class SerialPort
|
||||||
* @return Whether the port was successfully closed.
|
* @return Whether the port was successfully closed.
|
||||||
*/
|
*/
|
||||||
public final synchronized boolean closePort()
|
public final synchronized boolean closePort()
|
||||||
|
{
|
||||||
|
// Synchronize this method to the class scope as well
|
||||||
|
synchronized (SerialPort.class)
|
||||||
{
|
{
|
||||||
if (serialEventListener != null)
|
if (serialEventListener != null)
|
||||||
serialEventListener.stopListening();
|
serialEventListener.stopListening();
|
||||||
|
@ -510,6 +517,7 @@ public final class SerialPort
|
||||||
portHandle = closePortNative(portHandle);
|
portHandle = closePortNative(portHandle);
|
||||||
return (portHandle < 0);
|
return (portHandle < 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the port is currently open and available for communication.
|
* Returns whether the port is currently open and available for communication.
|
||||||
|
|
Loading…
Reference in New Issue