Browse Source

Switch to CountdownLatch.

pull/373/head
Greg Holmes 9 years ago
parent
commit
8f45c15e5c
2 changed files with 12 additions and 11 deletions
  1. 7
    6
      src/com/dmdirc/logger/ErrorManager.java
  2. 5
    5
      src/com/dmdirc/ui/FatalErrorDialog.java

+ 7
- 6
src/com/dmdirc/logger/ErrorManager.java View File

@@ -47,9 +47,9 @@ import java.util.Arrays;
47 47
 import java.util.Date;
48 48
 import java.util.LinkedList;
49 49
 import java.util.List;
50
+import java.util.concurrent.CountDownLatch;
50 51
 import java.util.concurrent.ExecutorService;
51 52
 import java.util.concurrent.Executors;
52
-import java.util.concurrent.Semaphore;
53 53
 
54 54
 import javax.inject.Inject;
55 55
 import javax.inject.Singleton;
@@ -75,7 +75,7 @@ public class ErrorManager {
75 75
     /** Listener list. */
76 76
     private final ListenerList errorListeners = new ListenerList();
77 77
     /** Semaphore used to wait for fatal error to report. */
78
-    private final Semaphore errorSemaphore = new Semaphore(2);
78
+    private final CountDownLatch errorSemaphore = new CountDownLatch(2);
79 79
     /** Event bus to subscribe and publish errors on. */
80 80
     private DMDircMBassador eventBus;
81 81
     /** Whether or not to send error reports. */
@@ -408,12 +408,13 @@ public class ErrorManager {
408 408
             }
409 409
             restart = false;
410 410
         } else {
411
-            errorSemaphore.acquireUninterruptibly(2);
412 411
             final FatalErrorDialog fed = new FatalErrorDialog(event.getError(), this, errorSemaphore);
413 412
             fed.setVisible(true);
414
-            //Wait for error status change to release semaphore
415
-            errorSemaphore.acquireUninterruptibly(2);
416
-            errorSemaphore.release();
413
+            try {
414
+                errorSemaphore.await();
415
+            } catch (InterruptedException ex) {
416
+                //Nevermind, carry on
417
+            }
417 418
             restart = fed.getRestart();
418 419
         }
419 420
 

+ 5
- 5
src/com/dmdirc/ui/FatalErrorDialog.java View File

@@ -33,7 +33,7 @@ import java.awt.Dimension;
33 33
 import java.awt.event.ActionEvent;
34 34
 import java.awt.event.ActionListener;
35 35
 import java.util.List;
36
-import java.util.concurrent.Semaphore;
36
+import java.util.concurrent.CountDownLatch;
37 37
 
38 38
 import javax.swing.BorderFactory;
39 39
 import javax.swing.Box;
@@ -84,7 +84,7 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
84 84
     /** Stack trace scroll pane. */
85 85
     private JScrollPane scrollPane;
86 86
     /** Error status semaphore. */
87
-    private final Semaphore errorSemaphore;
87
+    private final CountDownLatch errorSemaphore;
88 88
 
89 89
     /**
90 90
      * Creates a new fatal error dialog.
@@ -92,7 +92,7 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
92 92
      * @param error Error
93 93
      */
94 94
     public FatalErrorDialog(final ProgramError error, final ErrorManager errorManager,
95
-            final Semaphore errorSemaphore) {
95
+            final CountDownLatch errorSemaphore) {
96 96
         super(null, Dialog.ModalityType.TOOLKIT_MODAL);
97 97
 
98 98
         setModal(true);
@@ -236,7 +236,7 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
236 236
         } else {
237 237
             dispose();
238 238
         }
239
-        errorSemaphore.release();
239
+        errorSemaphore.countDown();
240 240
     }
241 241
 
242 242
     /**
@@ -305,7 +305,7 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
305 305
                 restartButton.setEnabled(status.isTerminal());
306 306
                 updateSendButtonText(status);
307 307
             });
308
-            errorSemaphore.release();
308
+            errorSemaphore.countDown();
309 309
         }
310 310
     }
311 311
 

Loading…
Cancel
Save