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:
akwizgran
2015-12-03 16:39:53 +00:00
parent 4f59491c9f
commit 8529c976c2
18 changed files with 180 additions and 179 deletions

View File

@@ -66,7 +66,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />

View File

@@ -61,9 +61,9 @@ Service, EventListener {
private final Executor dbExecutor;
private final EventBus eventBus;
private final Context appContext;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<ContactId, Integer> contactCounts =
new HashMap<ContactId, Integer>();
private final Map<GroupId, Integer> groupCounts =
@@ -112,7 +112,7 @@ Service, EventListener {
}
public void showPrivateMessageNotification(ContactId c) {
synchLock.lock();
lock.lock();
try {
Integer count = contactCounts.get(c);
if (count == null) contactCounts.put(c, 1);
@@ -120,23 +120,23 @@ Service, EventListener {
privateTotal++;
updatePrivateMessageNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void clearPrivateMessageNotification(ContactId c) {
synchLock.lock();
lock.lock();
try {
Integer count = contactCounts.remove(c);
if (count == null) return; // Already cleared
privateTotal -= count;
updatePrivateMessageNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Locking: synchLock
// Locking: lock
private void updatePrivateMessageNotification() {
if (privateTotal == 0) {
clearPrivateMessageNotification();
@@ -181,7 +181,7 @@ Service, EventListener {
}
}
// Locking: synchLock
// Locking: lock
private void clearPrivateMessageNotification() {
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
@@ -200,7 +200,7 @@ Service, EventListener {
}
public void showGroupPostNotification(GroupId g) {
synchLock.lock();
lock.lock();
try {
Integer count = groupCounts.get(g);
if (count == null) groupCounts.put(g, 1);
@@ -208,23 +208,23 @@ Service, EventListener {
groupTotal++;
updateGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void clearGroupPostNotification(GroupId g) {
synchLock.lock();
lock.lock();
try {
Integer count = groupCounts.remove(g);
if (count == null) return; // Already cleared
groupTotal -= count;
updateGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Locking: synchLock
// Locking: lock
private void updateGroupPostNotification() {
if (groupTotal == 0) {
clearGroupPostNotification();
@@ -269,7 +269,7 @@ Service, EventListener {
}
}
// Locking: synchLock
// Locking: lock
private void clearGroupPostNotification() {
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
@@ -277,7 +277,7 @@ Service, EventListener {
}
public void clearNotifications() {
synchLock.lock();
lock.lock();
try {
contactCounts.clear();
groupCounts.clear();
@@ -285,7 +285,7 @@ Service, EventListener {
clearPrivateMessageNotification();
clearGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
}

View File

@@ -15,15 +15,15 @@ class ReferenceManagerImpl implements ReferenceManager {
private static final Logger LOG =
Logger.getLogger(ReferenceManagerImpl.class.getName());
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<Class<?>, Map<Long, Object>> outerMap =
new HashMap<Class<?>, Map<Long, Object>>();
private long nextHandle = 0;
public <T> T getReference(long handle, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) {
@@ -36,13 +36,13 @@ class ReferenceManagerImpl implements ReferenceManager {
Object o = innerMap.get(handle);
return c.cast(o);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public <T> long putReference(T reference, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) {
@@ -57,12 +57,12 @@ class ReferenceManagerImpl implements ReferenceManager {
}
return handle;
} finally {
synchLock.unlock();
lock.unlock();
}
}
public <T> T removeReference(long handle, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) return null;
@@ -74,7 +74,7 @@ class ReferenceManagerImpl implements ReferenceManager {
}
return c.cast(o);
} finally {
synchLock.unlock();
lock.unlock();
}
}

View File

@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
@@ -28,5 +28,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="guice-3.0-no_aop" level="project" />
<orderEntry type="library" exported="" name="javax.inject" level="project" />
<orderEntry type="library" exported="" name="briar-api.briar-api" level="project" />
</component>
</module>

View File

@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
@@ -32,5 +32,6 @@
<orderEntry type="library" exported="" name="h2small-1.4.190" level="project" />
<orderEntry type="library" exported="" name="spongy-core-1.53" level="project" />
<orderEntry type="library" exported="" name="weupnp-0.1.3-SNAPSHOT-briar" level="project" />
<orderEntry type="library" exported="" name="briar-core.briar-core" level="project" />
</component>
</module>

View File

@@ -19,9 +19,9 @@ class FortunaGenerator {
private static final int KEY_BYTES = 32;
private static final int BLOCK_BYTES = 16;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final MessageDigest digest = new DoubleDigest(new SHA256Digest());
private final BlockCipher cipher = new AESLightEngine();
private final byte[] key = new byte[KEY_BYTES];
@@ -34,21 +34,21 @@ class FortunaGenerator {
}
void reseed(byte[] seed) {
synchLock.lock();
lock.lock();
try {
digest.update(key);
digest.update(seed);
digest.digest(key, 0, KEY_BYTES);
incrementCounter();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Package access for testing
void incrementCounter() {
synchLock.lock();
lock.lock();
try {
counter[0]++;
for (int i = 0; counter[i] == 0; i++) {
@@ -57,23 +57,23 @@ class FortunaGenerator {
counter[i + 1]++;
}
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Package access for testing
byte[] getCounter() {
synchLock.lock();
lock.lock();
try {
return counter;
} finally {
synchLock.unlock();
lock.unlock();
}
}
int nextBytes(byte[] dest, int off, int len) {
synchLock.lock();
lock.lock();
try {
// Don't write more than the maximum number of bytes in one request
if (len > MAX_BYTES_PER_REQUEST) len = MAX_BYTES_PER_REQUEST;
@@ -104,7 +104,7 @@ class FortunaGenerator {
// Return the number of bytes written
return len;
} finally {
synchLock.unlock();
lock.unlock();
}
}
}

View File

@@ -62,9 +62,9 @@ class ConnectorGroup extends Thread implements InvitationTask {
private final Collection<InvitationListener> listeners;
private final AtomicBoolean connected;
private final CountDownLatch localConfirmationLatch;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private int localConfirmationCode = -1, remoteConfirmationCode = -1;
private boolean connectionFailed = false;
private boolean localCompared = false, remoteCompared = false;
@@ -103,7 +103,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
public InvitationState addListener(InvitationListener l) {
synchLock.lock();
lock.lock();
try {
listeners.add(l);
return new InvitationState(localInvitationCode,
@@ -112,7 +112,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
localCompared, remoteCompared, localMatched, remoteMatched,
remoteName);
} finally {
synchLock.unlock();
lock.unlock();
}
}
@@ -134,11 +134,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
localProps = db.getLocalProperties();
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
synchLock.lock();
lock.lock();
try {
connectionFailed = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.connectionFailed();
return;
@@ -170,11 +170,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
// If none of the threads connected, inform the listeners
if (!connected.get()) {
synchLock.lock();
lock.lock();
try {
connectionFailed = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.connectionFailed();
}
@@ -203,23 +203,23 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
public void localConfirmationSucceeded() {
synchLock.lock();
lock.lock();
try {
localCompared = true;
localMatched = true;
} finally {
synchLock.unlock();
lock.unlock();
}
localConfirmationLatch.countDown();
}
public void localConfirmationFailed() {
synchLock.lock();
lock.lock();
try {
localCompared = true;
localMatched = false;
} finally {
synchLock.unlock();
lock.unlock();
}
localConfirmationLatch.countDown();
}
@@ -232,12 +232,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
void keyAgreementSucceeded(int localCode, int remoteCode) {
synchLock.lock();
lock.lock();
try {
localConfirmationCode = localCode;
remoteConfirmationCode = remoteCode;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners)
l.keyAgreementSucceeded(localCode, remoteCode);
@@ -249,43 +249,43 @@ class ConnectorGroup extends Thread implements InvitationTask {
boolean waitForLocalConfirmationResult() throws InterruptedException {
localConfirmationLatch.await(CONFIRMATION_TIMEOUT, MILLISECONDS);
synchLock.lock();
lock.lock();
try {
return localMatched;
} finally {
synchLock.unlock();
lock.unlock();
}
}
void remoteConfirmationSucceeded() {
synchLock.lock();
lock.lock();
try {
remoteCompared = true;
remoteMatched = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.remoteConfirmationSucceeded();
}
void remoteConfirmationFailed() {
synchLock.lock();
lock.lock();
try {
remoteCompared = true;
remoteMatched = false;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.remoteConfirmationFailed();
}
void pseudonymExchangeSucceeded(Author remoteAuthor) {
String name = remoteAuthor.getName();
synchLock.lock();
lock.lock();
try {
remoteName = name;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners)
l.pseudonymExchangeSucceeded(name);

View File

@@ -9,9 +9,9 @@ import org.briarproject.api.lifecycle.ShutdownManager;
class ShutdownManagerImpl implements ShutdownManager {
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
protected final Map<Integer, Thread> hooks;
private int nextHandle = 0;
@@ -20,7 +20,7 @@ class ShutdownManagerImpl implements ShutdownManager {
}
public int addShutdownHook(Runnable r) {
synchLock.lock();
lock.lock();
try {
int handle = nextHandle++;
Thread hook = createThread(r);
@@ -28,7 +28,7 @@ class ShutdownManagerImpl implements ShutdownManager {
Runtime.getRuntime().addShutdownHook(hook);
return handle;
} finally {
synchLock.unlock();
lock.unlock();
}
}
@@ -38,13 +38,13 @@ class ShutdownManagerImpl implements ShutdownManager {
}
public boolean removeShutdownHook(int handle) {
synchLock.lock();
lock.lock();
try {
Thread hook = hooks.remove(handle);
if (hook == null) return false;
else return Runtime.getRuntime().removeShutdownHook(hook);
} finally {
synchLock.unlock();
lock.unlock();
}
}

View File

@@ -27,9 +27,9 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
Logger.getLogger(ConnectionRegistryImpl.class.getName());
private final EventBus eventBus;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<TransportId, Map<ContactId, Integer>> connections;
private final Map<ContactId, Integer> contactCounts;
@@ -43,7 +43,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public void registerConnection(ContactId c, TransportId t) {
LOG.info("Connection registered");
boolean firstConnection = false;
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) {
@@ -61,7 +61,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
contactCounts.put(c, count + 1);
}
} finally {
synchLock.unlock();
lock.unlock();
}
if (firstConnection) {
@@ -73,7 +73,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public void unregisterConnection(ContactId c, TransportId t) {
LOG.info("Connection unregistered");
boolean lastConnection = false;
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) throw new IllegalArgumentException();
@@ -93,7 +93,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
contactCounts.put(c, count - 1);
}
} finally {
synchLock.unlock();
lock.unlock();
}
if (lastConnection) {
@@ -104,7 +104,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public Collection<ContactId> getConnectedContacts(
TransportId t) {
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) return Collections.emptyList();
@@ -112,17 +112,17 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
return Collections.unmodifiableList(ids);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public boolean isConnected(ContactId c) {
synchLock.lock();
lock.lock();
try {
return contactCounts.containsKey(c);
} finally {
synchLock.unlock();
lock.unlock();
}
}

View File

@@ -50,9 +50,9 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
private final TagRecogniser tagRecogniser;
private final Clock clock;
private final Timer timer;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<TransportId, Integer> maxLatencies;
private final Map<EndpointKey, TemporarySecret> oldSecrets;
private final Map<EndpointKey, TemporarySecret> currentSecrets;
@@ -75,7 +75,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
public boolean start() {
synchLock.lock();
lock.lock();
try {
eventBus.addListener(this);
// Load the temporary secrets and transport latencies from the DB
@@ -116,12 +116,12 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
MS_BETWEEN_CHECKS);
return true;
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Assigns secrets to the appropriate maps and returns any dead secrets
// Locking: synchLock
// Locking: lock
private Collection<TemporarySecret> assignSecretsToMaps(long now,
Collection<TemporarySecret> secrets) {
Collection<TemporarySecret> dead = new ArrayList<TemporarySecret>();
@@ -154,7 +154,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
// Replaces the given secrets and returns any secrets created
// Locking: synchLock
// Locking: lock
private Collection<TemporarySecret> replaceDeadSecrets(long now,
Collection<TemporarySecret> dead) {
// If there are several dead secrets for an endpoint, use the newest
@@ -213,7 +213,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
public boolean stop() {
synchLock.lock();
lock.lock();
try {
eventBus.removeListener(this);
timer.cancel();
@@ -224,13 +224,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
newSecrets.clear();
return true;
} finally {
synchLock.unlock();
lock.unlock();
}
}
public StreamContext getStreamContext(ContactId c,
TransportId t) {
synchLock.lock();
lock.lock();
try {
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
if (s == null) {
@@ -251,13 +251,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
byte[] secret = s.getSecret();
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void endpointAdded(Endpoint ep, int maxLatency,
byte[] initialSecret) {
synchLock.lock();
lock.lock();
try {
maxLatencies.put(ep.getTransportId(), maxLatency);
// Work out which rotation period we're in
@@ -291,13 +291,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
tagRecogniser.addSecret(s2);
tagRecogniser.addSecret(s3);
} finally {
synchLock.unlock();
lock.unlock();
}
}
@Override
public void run() {
synchLock.lock();
lock.lock();
try {
// Rebuild the maps because we may be running a whole period late
Collection<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
@@ -330,7 +330,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
for (TemporarySecret s : created) tagRecogniser.addSecret(s);
}
} finally {
synchLock.unlock();
lock.unlock();
}
}
@@ -347,14 +347,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
}
// Locking: synchLock
// Locking: lock
private void removeSecrets(ContactId c, Map<?, TemporarySecret> m) {
Iterator<TemporarySecret> it = m.values().iterator();
while (it.hasNext())
if (it.next().getContactId().equals(c)) it.remove();
}
// Locking: synchLock
// Locking: lock
private void removeSecrets(TransportId t, Map<?, TemporarySecret> m) {
Iterator<TemporarySecret> it = m.values().iterator();
while (it.hasNext())
@@ -403,13 +403,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
public void run() {
ContactId c = event.getContactId();
tagRecogniser.removeSecrets(c);
synchLock.lock();
lock.lock();
try {
removeSecrets(c, oldSecrets);
removeSecrets(c, currentSecrets);
removeSecrets(c, newSecrets);
} finally {
synchLock.unlock();
lock.unlock();
}
}
}
@@ -424,11 +424,11 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
@Override
public void run() {
synchLock.lock();
lock.lock();
try {
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
} finally {
synchLock.unlock();
lock.unlock();
}
}
}
@@ -445,14 +445,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
public void run() {
TransportId t = event.getTransportId();
tagRecogniser.removeSecrets(t);
synchLock.lock();
lock.lock();
try {
maxLatencies.remove(t);
removeSecrets(t, oldSecrets);
removeSecrets(t, currentSecrets);
removeSecrets(t, newSecrets);
} finally {
synchLock.unlock();
lock.unlock();
}
}
}

View File

@@ -20,9 +20,9 @@ class TagRecogniserImpl implements TagRecogniser {
private final CryptoComponent crypto;
private final DatabaseComponent db;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// Locking: synchLock
// Locking: lock
private final Map<TransportId, TransportTagRecogniser> recognisers;
@Inject
@@ -35,11 +35,11 @@ class TagRecogniserImpl implements TagRecogniser {
public StreamContext recogniseTag(TransportId t, byte[] tag)
throws DbException {
TransportTagRecogniser r;
synchLock.lock();
lock.lock();
try {
r = recognisers.get(t);
} finally {
synchLock.unlock();
lock.unlock();
}
if (r == null) return null;
return r.recogniseTag(tag);
@@ -48,7 +48,7 @@ class TagRecogniserImpl implements TagRecogniser {
public void addSecret(TemporarySecret s) {
TransportId t = s.getTransportId();
TransportTagRecogniser r;
synchLock.lock();
lock.lock();
try {
r = recognisers.get(t);
if (r == null) {
@@ -56,49 +56,49 @@ class TagRecogniserImpl implements TagRecogniser {
recognisers.put(t, r);
}
} finally {
synchLock.unlock();
lock.unlock();
}
r.addSecret(s);
}
public void removeSecret(ContactId c, TransportId t, long period) {
TransportTagRecogniser r;
synchLock.lock();
lock.lock();
try {
r = recognisers.get(t);
} finally {
synchLock.unlock();
lock.unlock();
}
if (r != null) r.removeSecret(c, period);
}
public void removeSecrets(ContactId c) {
synchLock.lock();
lock.lock();
try {
for (TransportTagRecogniser r : recognisers.values())
r.removeSecrets(c);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void removeSecrets(TransportId t) {
synchLock.lock();
lock.lock();
try {
recognisers.remove(t);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void removeSecrets() {
synchLock.lock();
lock.lock();
try {
for (TransportTagRecogniser r : recognisers.values())
r.removeSecrets();
} finally {
synchLock.unlock();
lock.unlock();
}
}

View File

@@ -29,9 +29,9 @@ class TransportTagRecogniser {
private final CryptoComponent crypto;
private final DatabaseComponent db;
private final TransportId transportId;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<Bytes, TagContext> tagMap;
private final Map<RemovalKey, RemovalContext> removalMap;
@@ -45,7 +45,7 @@ class TransportTagRecogniser {
}
StreamContext recogniseTag(byte[] tag) throws DbException {
synchLock.lock();
lock.lock();
try {
TagContext t = tagMap.remove(new Bytes(tag));
if (t == null) return null; // The tag was not expected
@@ -69,12 +69,12 @@ class TransportTagRecogniser {
return new StreamContext(t.contactId, transportId, t.secret,
t.streamNumber, t.alice);
} finally {
synchLock.unlock();
lock.unlock();
}
}
void addSecret(TemporarySecret s) {
synchLock.lock();
lock.lock();
try {
ContactId contactId = s.getContactId();
boolean alice = s.getAlice();
@@ -97,23 +97,23 @@ class TransportTagRecogniser {
RemovalContext r = new RemovalContext(window, secret, alice);
removalMap.put(new RemovalKey(contactId, period), r);
} finally {
synchLock.unlock();
lock.unlock();
}
}
void removeSecret(ContactId contactId, long period) {
synchLock.lock();
lock.lock();
try {
RemovalKey k = new RemovalKey(contactId, period);
RemovalContext removed = removalMap.remove(k);
if (removed == null) throw new IllegalArgumentException();
removeSecret(removed);
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Locking: synchLock
// Locking: lock
private void removeSecret(RemovalContext r) {
// Remove the expected tags
SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
@@ -126,7 +126,7 @@ class TransportTagRecogniser {
}
void removeSecrets(ContactId c) {
synchLock.lock();
lock.lock();
try {
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
for (RemovalKey k : removalMap.keySet())
@@ -134,18 +134,18 @@ class TransportTagRecogniser {
for (RemovalKey k : keysToRemove)
removeSecret(k.contactId, k.period);
} finally {
synchLock.unlock();
lock.unlock();
}
}
void removeSecrets() {
synchLock.lock();
lock.lock();
try {
for (RemovalContext r : removalMap.values()) removeSecret(r);
assert tagMap.isEmpty();
removalMap.clear();
} finally {
synchLock.unlock();
lock.unlock();
}
}

View File

@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />

View File

@@ -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);
}
}

View File

@@ -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));

View File

@@ -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);

View File

@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="briar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" version="4">
<module external.linked.project.id="briar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>