Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2017-06-15 15:15:40 +0000
committerDoug Schaefer2017-06-15 15:15:40 +0000
commitff9289d396ec9b3a65b6ba864d5daf41972a179d (patch)
treed9162400511a2d32ff7912eb77ad22160236eb7e
parent64f1d0b5d96d245272e1fd5f42803dabe614d1a1 (diff)
downloadorg.eclipse.launchbar-ff9289d396ec9b3a65b6ba864d5daf41972a179d.tar.gz
org.eclipse.launchbar-ff9289d396ec9b3a65b6ba864d5daf41972a179d.tar.xz
org.eclipse.launchbar-ff9289d396ec9b3a65b6ba864d5daf41972a179d.zip
Even better solution for the deadlock on startup.
Make sure we aren't locked when calling the listeners. Change-Id: Id67f52013646733347c3ac0e45ef0a32953c9e89
-rw-r--r--bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java72
1 files changed, 40 insertions, 32 deletions
diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
index 2749824..283b53a 100644
--- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
+++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
@@ -11,6 +11,7 @@
package org.eclipse.launchbar.core.internal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -607,18 +608,31 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
}
+ private interface FireAction {
+ void run(ILaunchBarListener listener);
+ }
+
+ private void fireEvent(FireAction action) {
+ Collection<ILaunchBarListener> l;
+ synchronized (listeners) {
+ l = new ArrayList<>(listeners);
+ }
+
+ for (ILaunchBarListener listener : l) {
+ action.run(listener);
+ }
+ }
+
private void fireActiveLaunchDescriptorChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchDescriptorChanged(activeLaunchDesc);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchDescriptorChanged(activeLaunchDesc);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
@Override
@@ -675,15 +689,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireActiveLaunchModeChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchModeChanged(activeLaunchMode);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchModeChanged(activeLaunchMode);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
@@ -768,15 +780,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireActiveLaunchTargetChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchTargetChanged(activeLaunchTarget);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchTargetChanged(activeLaunchTarget);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) {
@@ -922,15 +932,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireLaunchTargetsChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.launchTargetsChanged();
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.launchTargetsChanged();
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
@Override

Back to the top