Comments to indicate which locks guard which variables.

This commit is contained in:
akwizgran
2015-01-29 11:05:46 +00:00
parent 47bd84122e
commit 0dbfd7073f
21 changed files with 235 additions and 1092 deletions

View File

@@ -20,12 +20,11 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
private final RemovableDriveFinder finder;
private final int pollingInterval;
private volatile boolean running = false;
private volatile Callback callback = null;
private final Lock pollingLock = new ReentrantLock();
private final Condition stopPolling = pollingLock.newCondition();
private volatile boolean running = false;
private volatile Callback callback = null;
public PollingRemovableDriveMonitor(Executor ioExecutor,
RemovableDriveFinder finder, int pollingInterval) {

View File

@@ -1,83 +0,0 @@
package org.briarproject.plugins.file;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
private static final Logger LOG =
Logger.getLogger(PollingRemovableDriveMonitor.class.getName());
private final Executor ioExecutor;
private final RemovableDriveFinder finder;
<<<<<<< HEAD
private final long pollingInterval;
=======
private final int pollingInterval;
private final Object pollingLock = new Object();
>>>>>>> theSource
private volatile boolean running = false;
private volatile Callback callback = null;
private final Lock pollingLock = new ReentrantLock();
private final Condition stopPolling = pollingLock.newCondition();
public PollingRemovableDriveMonitor(Executor ioExecutor,
RemovableDriveFinder finder, int pollingInterval) {
this.ioExecutor = ioExecutor;
this.finder = finder;
this.pollingInterval = pollingInterval;
}
public void start(Callback callback) throws IOException {
this.callback = callback;
running = true;
ioExecutor.execute(this);
}
public void stop() throws IOException {
running = false;
pollingLock.lock();
try {
stopPolling.signalAll();
}
finally {
pollingLock.unlock();
}
}
public void run() {
try {
Collection<File> drives = finder.findRemovableDrives();
while(running) {
pollingLock.lock();
try {
stopPolling.await(pollingInterval, TimeUnit.MILLISECONDS);
}
finally{
pollingLock.unlock();
}
if(!running) return;
Collection<File> newDrives = finder.findRemovableDrives();
for(File f : newDrives) {
if(!drives.contains(f)) callback.driveInserted(f);
}
drives = newDrives;
}
} catch(InterruptedException e) {
LOG.warning("Interrupted while waiting to poll");
Thread.currentThread().interrupt();
} catch(IOException e) {
callback.exceptionThrown(e);
}
}
}

View File

@@ -13,20 +13,22 @@ import net.contentobjects.jnotify.JNotifyListener;
abstract class UnixRemovableDriveMonitor implements RemovableDriveMonitor,
JNotifyListener {
//TODO: rationalise this in a further refactor
private static final Lock staticSynchLock = new ReentrantLock();
// The following are locking: staticSynchLock
private static boolean triedLoad = false;
private static Throwable loadError = null;
private final List<Integer> watches = new ArrayList<Integer>();
private final Lock synchLock = new ReentrantLock();
// The following are locking: synchLock
private final List<Integer> watches = new ArrayList<Integer>();
private boolean started = false;
private Callback callback = null;
protected abstract String[] getPathsToWatch();
//TODO: rationalise this in a further refactor
private final Lock synchLock = new ReentrantLock();
private static final Lock staticSynchLock = new ReentrantLock();
private static Throwable tryLoad() {
try {
Class.forName("net.contentobjects.jnotify.JNotify");