Browse Source

Don't hold locks while calling identity listeners

Fixes deadlock when setting some options to their default values

Change-Id: Ibfb91261db177bc7cdcd8d9d594fecbed789b718
Reviewed-on: http://gerrit.dmdirc.com/732
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 years ago
parent
commit
5a8238e4d8
1 changed files with 15 additions and 6 deletions
  1. 15
    6
      src/com/dmdirc/config/Identity.java

+ 15
- 6
src/com/dmdirc/config/Identity.java View File

348
     public void setOption(final String domain, final String option,
348
     public void setOption(final String domain, final String option,
349
             final String value) {
349
             final String value) {
350
         String oldValue;
350
         String oldValue;
351
+        boolean unset = false;
351
 
352
 
352
         synchronized (this) {
353
         synchronized (this) {
353
             oldValue = getOption(domain, option);
354
             oldValue = getOption(domain, option);
365
 
366
 
366
                 if (globalConfig.hasOption(domain, option)
367
                 if (globalConfig.hasOption(domain, option)
367
                         && globalConfig.getOption(domain, option).equals(value)) {
368
                         && globalConfig.getOption(domain, option).equals(value)) {
369
+                    // The new value is covered by a default setting
368
                     if (oldValue == null) {
370
                     if (oldValue == null) {
371
+                        // There was no old value, so we don't need to do anything
369
                         return;
372
                         return;
370
                     } else {
373
                     } else {
371
-                        unsetOption(domain, option);
372
-                        return;
374
+                        // There was an old value, so we need to unset it so
375
+                        // that the default shows through.
376
+                        file.getKeyDomain(domain).remove(option);
377
+                        needSave = true;
378
+                        unset = true;
373
                     }
379
                     }
374
                 }
380
                 }
375
             }
381
             }
376
-        }
377
 
382
 
378
-        if ((oldValue == null && value != null)
379
-                || (oldValue != null && !oldValue.equals(value))) {
380
-            synchronized (this) {
383
+            if (!unset && ((oldValue == null && value != null)
384
+                    || (oldValue != null && !oldValue.equals(value)))) {
381
                 file.getKeyDomain(domain).put(option, value);
385
                 file.getKeyDomain(domain).put(option, value);
382
                 needSave = true;
386
                 needSave = true;
383
             }
387
             }
388
+        }
384
 
389
 
390
+        // Fire any setting change listeners now we're no longer holding
391
+        // a lock on this identity.
392
+        if (unset || (oldValue == null && value != null)
393
+                || (oldValue != null && !oldValue.equals(value))) {
385
             fireSettingChange(domain, option);
394
             fireSettingChange(domain, option);
386
         }
395
         }
387
     }
396
     }

Loading…
Cancel
Save