forked from I2P_Developers/i2p.i2p
split up big lock to avoid deadlocks
This commit is contained in:
@ -109,8 +109,13 @@ public class I2PAppContext {
|
|||||||
private File _logDir;
|
private File _logDir;
|
||||||
private File _appDir;
|
private File _appDir;
|
||||||
private File _tmpDir;
|
private File _tmpDir;
|
||||||
|
// split up big lock on this to avoid deadlocks
|
||||||
|
private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(), _lock4 = new Object(),
|
||||||
|
_lock5 = new Object(), _lock6 = new Object(), _lock7 = new Object(), _lock8 = new Object(),
|
||||||
|
_lock9 = new Object(), _lock10 = new Object(), _lock11 = new Object(), _lock12 = new Object(),
|
||||||
|
_lock13 = new Object(), _lock14 = new Object(), _lock15 = new Object(), _lock16 = new Object(),
|
||||||
|
_lock17 = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull the default context, creating a new one if necessary, else using
|
* Pull the default context, creating a new one if necessary, else using
|
||||||
* the first one created.
|
* the first one created.
|
||||||
@ -385,7 +390,7 @@ public class I2PAppContext {
|
|||||||
*/
|
*/
|
||||||
public File getTempDir() {
|
public File getTempDir() {
|
||||||
// fixme don't synchronize every time
|
// fixme don't synchronize every time
|
||||||
synchronized (this) {
|
synchronized (_lock1) {
|
||||||
if (_tmpDir == null) {
|
if (_tmpDir == null) {
|
||||||
String d = getProperty("i2p.dir.temp", System.getProperty("java.io.tmpdir"));
|
String d = getProperty("i2p.dir.temp", System.getProperty("java.io.tmpdir"));
|
||||||
// our random() probably isn't warmed up yet
|
// our random() probably isn't warmed up yet
|
||||||
@ -409,7 +414,7 @@ public class I2PAppContext {
|
|||||||
|
|
||||||
/** don't rely on deleteOnExit() */
|
/** don't rely on deleteOnExit() */
|
||||||
public void deleteTempDir() {
|
public void deleteTempDir() {
|
||||||
synchronized (this) {
|
synchronized (_lock1) {
|
||||||
if (_tmpDir != null) {
|
if (_tmpDir != null) {
|
||||||
FileUtil.rmdir(_tmpDir, false);
|
FileUtil.rmdir(_tmpDir, false);
|
||||||
_tmpDir = null;
|
_tmpDir = null;
|
||||||
@ -543,7 +548,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeStatManager() {
|
private void initializeStatManager() {
|
||||||
synchronized (this) {
|
synchronized (_lock2) {
|
||||||
if (_statManager == null)
|
if (_statManager == null)
|
||||||
_statManager = new StatManager(this);
|
_statManager = new StatManager(this);
|
||||||
_statManagerInitialized = true;
|
_statManagerInitialized = true;
|
||||||
@ -570,7 +575,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSessionKeyManager() {
|
private void initializeSessionKeyManager() {
|
||||||
synchronized (this) {
|
synchronized (_lock3) {
|
||||||
if (_sessionKeyManager == null)
|
if (_sessionKeyManager == null)
|
||||||
//_sessionKeyManager = new PersistentSessionKeyManager(this);
|
//_sessionKeyManager = new PersistentSessionKeyManager(this);
|
||||||
_sessionKeyManager = new TransientSessionKeyManager(this);
|
_sessionKeyManager = new TransientSessionKeyManager(this);
|
||||||
@ -590,7 +595,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeNamingService() {
|
private void initializeNamingService() {
|
||||||
synchronized (this) {
|
synchronized (_lock4) {
|
||||||
if (_namingService == null) {
|
if (_namingService == null) {
|
||||||
_namingService = NamingService.createInstance(this);
|
_namingService = NamingService.createInstance(this);
|
||||||
}
|
}
|
||||||
@ -613,7 +618,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeElGamalEngine() {
|
private void initializeElGamalEngine() {
|
||||||
synchronized (this) {
|
synchronized (_lock5) {
|
||||||
if (_elGamalEngine == null) {
|
if (_elGamalEngine == null) {
|
||||||
if ("off".equals(getProperty("i2p.encryption", "on")))
|
if ("off".equals(getProperty("i2p.encryption", "on")))
|
||||||
_elGamalEngine = new DummyElGamalEngine(this);
|
_elGamalEngine = new DummyElGamalEngine(this);
|
||||||
@ -638,7 +643,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeElGamalAESEngine() {
|
private void initializeElGamalAESEngine() {
|
||||||
synchronized (this) {
|
synchronized (_lock6) {
|
||||||
if (_elGamalAESEngine == null)
|
if (_elGamalAESEngine == null)
|
||||||
_elGamalAESEngine = new ElGamalAESEngine(this);
|
_elGamalAESEngine = new ElGamalAESEngine(this);
|
||||||
_elGamalAESEngineInitialized = true;
|
_elGamalAESEngineInitialized = true;
|
||||||
@ -658,7 +663,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAESEngine() {
|
private void initializeAESEngine() {
|
||||||
synchronized (this) {
|
synchronized (_lock7) {
|
||||||
if (_AESEngine == null) {
|
if (_AESEngine == null) {
|
||||||
if ("off".equals(getProperty("i2p.encryption", "on")))
|
if ("off".equals(getProperty("i2p.encryption", "on")))
|
||||||
_AESEngine = new AESEngine(this);
|
_AESEngine = new AESEngine(this);
|
||||||
@ -682,7 +687,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeLogManager() {
|
private void initializeLogManager() {
|
||||||
synchronized (this) {
|
synchronized (_lock8) {
|
||||||
if (_logManager == null)
|
if (_logManager == null)
|
||||||
_logManager = new LogManager(this);
|
_logManager = new LogManager(this);
|
||||||
_logManagerInitialized = true;
|
_logManagerInitialized = true;
|
||||||
@ -701,7 +706,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeHMAC() {
|
private void initializeHMAC() {
|
||||||
synchronized (this) {
|
synchronized (_lock9) {
|
||||||
if (_hmac == null) {
|
if (_hmac == null) {
|
||||||
_hmac= new HMACGenerator(this);
|
_hmac= new HMACGenerator(this);
|
||||||
}
|
}
|
||||||
@ -718,7 +723,7 @@ public class I2PAppContext {
|
|||||||
|
|
||||||
/** @deprecated used only by syndie */
|
/** @deprecated used only by syndie */
|
||||||
private void initializeHMAC256() {
|
private void initializeHMAC256() {
|
||||||
synchronized (this) {
|
synchronized (_lock10) {
|
||||||
if (_hmac256 == null) {
|
if (_hmac256 == null) {
|
||||||
_hmac256 = new HMAC256Generator(this);
|
_hmac256 = new HMAC256Generator(this);
|
||||||
}
|
}
|
||||||
@ -737,7 +742,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSHA() {
|
private void initializeSHA() {
|
||||||
synchronized (this) {
|
synchronized (_lock11) {
|
||||||
if (_sha == null)
|
if (_sha == null)
|
||||||
_sha= new SHA256Generator(this);
|
_sha= new SHA256Generator(this);
|
||||||
_shaInitialized = true;
|
_shaInitialized = true;
|
||||||
@ -755,7 +760,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDSA() {
|
private void initializeDSA() {
|
||||||
synchronized (this) {
|
synchronized (_lock12) {
|
||||||
if (_dsa == null) {
|
if (_dsa == null) {
|
||||||
if ("off".equals(getProperty("i2p.encryption", "on")))
|
if ("off".equals(getProperty("i2p.encryption", "on")))
|
||||||
_dsa = new DummyDSAEngine(this);
|
_dsa = new DummyDSAEngine(this);
|
||||||
@ -777,7 +782,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeKeyGenerator() {
|
private void initializeKeyGenerator() {
|
||||||
synchronized (this) {
|
synchronized (_lock13) {
|
||||||
if (_keyGenerator == null)
|
if (_keyGenerator == null)
|
||||||
_keyGenerator = new KeyGenerator(this);
|
_keyGenerator = new KeyGenerator(this);
|
||||||
_keyGeneratorInitialized = true;
|
_keyGeneratorInitialized = true;
|
||||||
@ -796,7 +801,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeClock() { // overridden in RouterContext
|
protected void initializeClock() { // overridden in RouterContext
|
||||||
synchronized (this) {
|
synchronized (_lock14) {
|
||||||
if (_clock == null)
|
if (_clock == null)
|
||||||
_clock = new Clock(this);
|
_clock = new Clock(this);
|
||||||
_clockInitialized = true;
|
_clockInitialized = true;
|
||||||
@ -817,7 +822,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeRoutingKeyGenerator() {
|
private void initializeRoutingKeyGenerator() {
|
||||||
synchronized (this) {
|
synchronized (_lock15) {
|
||||||
if (_routingKeyGenerator == null)
|
if (_routingKeyGenerator == null)
|
||||||
_routingKeyGenerator = new RoutingKeyGenerator(this);
|
_routingKeyGenerator = new RoutingKeyGenerator(this);
|
||||||
_routingKeyGeneratorInitialized = true;
|
_routingKeyGeneratorInitialized = true;
|
||||||
@ -834,7 +839,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeKeyRing() {
|
protected void initializeKeyRing() {
|
||||||
synchronized (this) {
|
synchronized (_lock16) {
|
||||||
if (_keyRing == null)
|
if (_keyRing == null)
|
||||||
_keyRing = new KeyRing();
|
_keyRing = new KeyRing();
|
||||||
_keyRingInitialized = true;
|
_keyRingInitialized = true;
|
||||||
@ -852,7 +857,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeRandom() {
|
private void initializeRandom() {
|
||||||
synchronized (this) {
|
synchronized (_lock17) {
|
||||||
if (_random == null) {
|
if (_random == null) {
|
||||||
//if (true)
|
//if (true)
|
||||||
_random = new FortunaRandomSource(this);
|
_random = new FortunaRandomSource(this);
|
||||||
|
@ -59,6 +59,8 @@ public class RouterContext extends I2PAppContext {
|
|||||||
private MessageStateMonitor _messageStateMonitor;
|
private MessageStateMonitor _messageStateMonitor;
|
||||||
private RouterThrottle _throttle;
|
private RouterThrottle _throttle;
|
||||||
private final Set<Runnable> _finalShutdownTasks;
|
private final Set<Runnable> _finalShutdownTasks;
|
||||||
|
// split up big lock on this to avoid deadlocks
|
||||||
|
private final Object _lock1 = new Object(), _lock2 = new Object();
|
||||||
|
|
||||||
private static List<RouterContext> _contexts = new ArrayList(1);
|
private static List<RouterContext> _contexts = new ArrayList(1);
|
||||||
|
|
||||||
@ -411,7 +413,7 @@ public class RouterContext extends I2PAppContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initializeClock() {
|
protected void initializeClock() {
|
||||||
synchronized (this) {
|
synchronized (_lock1) {
|
||||||
if (_clock == null)
|
if (_clock == null)
|
||||||
_clock = new RouterClock(this);
|
_clock = new RouterClock(this);
|
||||||
_clockInitialized = true;
|
_clockInitialized = true;
|
||||||
@ -428,7 +430,7 @@ public class RouterContext extends I2PAppContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initializeKeyRing() {
|
protected void initializeKeyRing() {
|
||||||
synchronized (this) {
|
synchronized (_lock2) {
|
||||||
if (_keyRing == null)
|
if (_keyRing == null)
|
||||||
_keyRing = new PersistentKeyRing(this);
|
_keyRing = new PersistentKeyRing(this);
|
||||||
_keyRingInitialized = true;
|
_keyRingInitialized = true;
|
||||||
|
Reference in New Issue
Block a user