mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Renamed a bunch of lock variables.
"synchLock" will become confusing when we have lots of objects with "sync" in the name.
This commit is contained in:
@@ -38,9 +38,9 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
private static final int WS_MINIMIZE = 0x20000000;
|
||||
|
||||
private final Map<String, Object> options;
|
||||
private final Lock synchLock = new ReentrantLock();
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
private boolean initialised = false; // Locking: synchLock
|
||||
private boolean initialised = false; // Locking: lock
|
||||
|
||||
WindowsShutdownManagerImpl() {
|
||||
// Use the Unicode versions of Win32 API calls
|
||||
@@ -52,12 +52,12 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
|
||||
@Override
|
||||
public int addShutdownHook(Runnable r) {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (!initialised) initialise();
|
||||
return super.addShutdownHook(r);
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
return new StartOnce(r);
|
||||
}
|
||||
|
||||
// Locking: synchLock
|
||||
// Locking: lock
|
||||
private void initialise() {
|
||||
if (OsUtils.isWindows()) {
|
||||
new EventLoop().start();
|
||||
@@ -78,7 +78,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
|
||||
// Package access for testing
|
||||
void runShutdownHooks() {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
boolean interrupted = false;
|
||||
// Start each hook in its own thread
|
||||
@@ -94,7 +94,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
}
|
||||
if (interrupted) Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private static interface User32 extends StdCallLibrary {
|
||||
private interface User32 extends StdCallLibrary {
|
||||
|
||||
HWND CreateWindowEx(int styleEx, String className, String windowName,
|
||||
int style, int x, int y, int width, int height, HWND parent,
|
||||
@@ -177,8 +177,8 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
LRESULT DispatchMessage(MSG msg);
|
||||
}
|
||||
|
||||
private static interface WindowProc extends StdCallCallback {
|
||||
private interface WindowProc extends StdCallCallback {
|
||||
|
||||
public LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
||||
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,15 @@ abstract class UnixRemovableDriveMonitor implements RemovableDriveMonitor,
|
||||
JNotifyListener {
|
||||
|
||||
//TODO: rationalise this in a further refactor
|
||||
private static final Lock staticSynchLock = new ReentrantLock();
|
||||
private static final Lock staticLock = new ReentrantLock();
|
||||
|
||||
// The following are locking: staticSynchLock
|
||||
// The following are locking: staticLock
|
||||
private static boolean triedLoad = false;
|
||||
private static Throwable loadError = null;
|
||||
|
||||
private final Lock synchLock = new ReentrantLock();
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
// The following are locking: synchLock
|
||||
// The following are locking: lock
|
||||
private final List<Integer> watches = new ArrayList<Integer>();
|
||||
private boolean started = false;
|
||||
private Callback callback = null;
|
||||
@@ -41,7 +41,7 @@ JNotifyListener {
|
||||
}
|
||||
|
||||
public static void checkEnabled() throws IOException {
|
||||
staticSynchLock.lock();
|
||||
staticLock.lock();
|
||||
try {
|
||||
if (!triedLoad) {
|
||||
loadError = tryLoad();
|
||||
@@ -49,7 +49,7 @@ JNotifyListener {
|
||||
}
|
||||
if (loadError != null) throw new IOException(loadError.toString());
|
||||
} finally {
|
||||
staticSynchLock.unlock();
|
||||
staticLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ JNotifyListener {
|
||||
if (new File(path).exists())
|
||||
watches.add(JNotify.addWatch(path, mask, false, this));
|
||||
}
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
assert !started;
|
||||
assert this.callback == null;
|
||||
@@ -69,14 +69,14 @@ JNotifyListener {
|
||||
this.callback = callback;
|
||||
this.watches.addAll(watches);
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws IOException {
|
||||
checkEnabled();
|
||||
List<Integer> watches;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
assert started;
|
||||
assert callback != null;
|
||||
@@ -85,18 +85,18 @@ JNotifyListener {
|
||||
watches = new ArrayList<Integer>(this.watches);
|
||||
this.watches.clear();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
for (Integer w : watches) JNotify.removeWatch(w);
|
||||
}
|
||||
|
||||
public void fileCreated(int wd, String rootPath, String name) {
|
||||
Callback callback;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
callback = this.callback;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
if (callback != null)
|
||||
callback.driveInserted(new File(rootPath + "/" + name));
|
||||
|
||||
@@ -44,11 +44,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
private final Semaphore stateChange;
|
||||
private final byte[] line;
|
||||
|
||||
private final Lock synchLock = new ReentrantLock();
|
||||
private final Condition connectedStateChanged = synchLock.newCondition();
|
||||
private final Condition initialisedStateChanged = synchLock.newCondition();
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Condition connectedStateChanged = lock.newCondition();
|
||||
private final Condition initialisedStateChanged = lock.newCondition();
|
||||
|
||||
// The following are locking: synchLock
|
||||
// The following are locking: lock
|
||||
private ReliabilityLayer reliability = null;
|
||||
private boolean initialised = false, connected = false;
|
||||
|
||||
@@ -100,7 +100,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
// Wait for the event thread to receive "OK"
|
||||
boolean success = false;
|
||||
try {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
long now = clock.currentTimeMillis();
|
||||
long end = now + OK_TIMEOUT;
|
||||
@@ -110,7 +110,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
success = initialised;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
tryToClose(port);
|
||||
@@ -135,7 +135,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
|
||||
public void stop() throws IOException {
|
||||
LOG.info("Stopping");
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
// Wake any threads that are waiting to connect
|
||||
initialised = false;
|
||||
@@ -143,7 +143,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
initialisedStateChanged.signalAll();
|
||||
connectedStateChanged.signalAll();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
// Hang up if necessary and close the port
|
||||
try {
|
||||
@@ -164,7 +164,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
// Locking: stateChange
|
||||
private void hangUpInner() throws IOException {
|
||||
ReliabilityLayer reliability;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (this.reliability == null) {
|
||||
LOG.info("Not hanging up - already on the hook");
|
||||
@@ -174,7 +174,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
this.reliability = null;
|
||||
connected = false;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
reliability.stop();
|
||||
LOG.info("Hanging up");
|
||||
@@ -201,7 +201,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
try {
|
||||
ReliabilityLayer reliability =
|
||||
reliabilityFactory.createReliabilityLayer(this);
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (!initialised) {
|
||||
LOG.info("Not dialling - modem not initialised");
|
||||
@@ -213,7 +213,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
this.reliability = reliability;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
reliability.start();
|
||||
LOG.info("Dialling");
|
||||
@@ -226,7 +226,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
// Wait for the event thread to receive "CONNECT"
|
||||
try {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
long now = clock.currentTimeMillis();
|
||||
long end = now + CONNECT_TIMEOUT;
|
||||
@@ -236,7 +236,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
if (connected) return true;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
tryToClose(port);
|
||||
@@ -252,11 +252,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
ReliabilityLayer reliability;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
reliability = this.reliability;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
if (reliability == null) throw new IOException("Not connected");
|
||||
return reliability.getInputStream();
|
||||
@@ -264,11 +264,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
ReliabilityLayer reliability;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
reliability = this.reliability;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
if (reliability == null) throw new IOException("Not connected");
|
||||
return reliability.getOutputStream();
|
||||
@@ -319,11 +319,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
|
||||
private boolean handleData(byte[] b) throws IOException {
|
||||
ReliabilityLayer reliability;
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
reliability = this.reliability;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
if (reliability == null) return false;
|
||||
reliability.handleRead(b);
|
||||
@@ -343,12 +343,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
lineLen = 0;
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Modem status: " + s);
|
||||
if (s.startsWith("CONNECT")) {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
connected = true;
|
||||
connectedStateChanged.signalAll();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
// There might be data in the buffer as well as text
|
||||
int off = i + 1;
|
||||
@@ -360,20 +360,20 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
return;
|
||||
} else if (s.equals("BUSY") || s.equals("NO DIALTONE")
|
||||
|| s.equals("NO CARRIER")) {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
connected = false;
|
||||
connectedStateChanged.signalAll();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
} else if (s.equals("OK")) {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
initialised = true;
|
||||
initialisedStateChanged.signalAll();
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
} else if (s.equals("RING")) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@@ -401,7 +401,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
try {
|
||||
ReliabilityLayer reliability =
|
||||
reliabilityFactory.createReliabilityLayer(this);
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (!initialised) {
|
||||
LOG.info("Not answering - modem not initialised");
|
||||
@@ -413,7 +413,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
this.reliability = reliability;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
reliability.start();
|
||||
LOG.info("Answering");
|
||||
@@ -426,7 +426,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
// Wait for the event thread to receive "CONNECT"
|
||||
boolean success = false;
|
||||
try {
|
||||
synchLock.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
long now = clock.currentTimeMillis();
|
||||
long end = now + CONNECT_TIMEOUT;
|
||||
@@ -436,7 +436,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
||||
}
|
||||
success = connected;
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
tryToClose(port);
|
||||
|
||||
Reference in New Issue
Block a user