Synchronize open/close on class as well as instance
This commit is contained in:
parent
bcc9e1e19f
commit
b52271c48c
|
@ -7,7 +7,7 @@ buildscript {
|
|||
|
||||
plugins {
|
||||
id 'maven-publish'
|
||||
id 'biz.aQute.bnd.builder' version '5.0.0'
|
||||
id 'biz.aQute.bnd.builder' version '6.0.0'
|
||||
}
|
||||
|
||||
group = 'com.fazecast'
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort.java
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: Nov 12, 2021
|
||||
* Last Updated on: Nov 19, 2021
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
safetySleepTimeMS = safetySleepTime;
|
||||
|
@ -469,6 +472,7 @@ public final class SerialPort
|
|||
}
|
||||
return (portHandle > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public final synchronized boolean closePort()
|
||||
{
|
||||
// Synchronize this method to the class scope as well
|
||||
synchronized (SerialPort.class)
|
||||
{
|
||||
if (serialEventListener != null)
|
||||
serialEventListener.stopListening();
|
||||
|
@ -510,6 +517,7 @@ public final class SerialPort
|
|||
portHandle = closePortNative(portHandle);
|
||||
return (portHandle < 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the port is currently open and available for communication.
|
||||
|
|
Loading…
Reference in New Issue