Do

Merge lp://staging/~alexlauni/do/clear-universe into lp://staging/do

Proposed by Alex Launi
Status: Rejected
Rejected by: Alex Launi
Proposed branch: lp://staging/~alexlauni/do/clear-universe
Merge into: lp://staging/do
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~alexlauni/do/clear-universe
Reviewer Review Type Date Requested Status
Jason Smith (community) Needs Fixing
Robert Dyer (community) Approve
David Siegel Pending
Review via email: mp+7838@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Fixes bug where our items are not actually leaving universe when a plugin is being disabled.

Revision history for this message
Robert Dyer (psybers) :
review: Approve
Revision history for this message
Jason Smith (jassmith) wrote :

This fix causes there to be a momentary issue where the universe will be in a partially complete state, I am going to push a branch with a proper fix in a moment and propose

review: Needs Fixing

Unmerged revisions

1253. By Alex Launi

Remove all items from Universe on a refresh, not just the ones provided by plugins

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do/gtk-gui/gui.stetic'
2--- Do/gtk-gui/gui.stetic 2009-06-21 02:20:30 +0000
3+++ Do/gtk-gui/gui.stetic 2009-06-24 09:50:36 +0000
4@@ -6,9 +6,6 @@
5 </configuration>
6 <import>
7 <widget-library name="Mono.Addins.Gui, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
8- <widget-library name="../../Do.Platform.Linux/bin/Debug/Do.Platform.Linux.dll" />
9- <widget-library name="../../Do.Interface.Linux/bin/Debug/Do.Interface.Linux.dll" />
10- <widget-library name="../../Do.Interface.Linux.AnimationBase/bin/Debug/Do.Interface.Linux.AnimationBase.dll" />
11 <widget-library name="../bin/Debug/Do.exe" internal="true" />
12 </import>
13 <widget class="Gtk.Window" id="Do.UI.PreferencesWindow" design-size="450 470">
14
15=== modified file 'Do/src/Do.Core/UniverseManager.cs'
16--- Do/src/Do.Core/UniverseManager.cs 2009-06-21 02:20:30 +0000
17+++ Do/src/Do.Core/UniverseManager.cs 2009-06-24 09:50:36 +0000
18@@ -35,6 +35,7 @@
19 {
20
21 Thread update_thread;
22+ object universe_lock;
23 Dictionary<string, Item> universe;
24 EventHandler initialized;
25
26@@ -75,6 +76,7 @@
27
28 public UniverseManager ()
29 {
30+ universe_lock = new object ();
31 universe = new Dictionary<string, Item> ();
32
33 update_thread = new Thread (new ThreadStart (UniverseUpdateLoop));
34@@ -117,7 +119,7 @@
35
36 public IEnumerable<Item> Search (string query, IEnumerable<Type> filter, Item other)
37 {
38- lock (universe)
39+ lock (universe_lock)
40 return Search (query, filter, universe.Values, other);
41 }
42
43@@ -184,12 +186,8 @@
44 /// </summary>
45 void ReloadActions ()
46 {
47- Log<UniverseManager>.Debug ("Reloading actions...");
48- lock (universe) {
49- foreach (Act action in PluginManager.Actions) {
50- if (universe.ContainsKey (action.UniqueId))
51- universe.Remove (action.UniqueId);
52- }
53+ lock (universe_lock) {
54+ Log<UniverseManager>.Debug ("Reloading actions...");
55 foreach (Act action in PluginManager.Actions)
56 universe [action.UniqueId] = action;
57 }
58@@ -203,23 +201,18 @@
59 void ReloadSource (ItemSource source)
60 {
61 SafeItemSource safeSource;
62- IEnumerable<Item> oldItems, newItems;
63+ IEnumerable<Item> newItems;
64
65 if (source == null) throw new ArgumentNullException ("source");
66
67 safeSource = source.RetainSafe ();
68- oldItems = safeSource.Items;
69 // We call UpdateItems outside of the lock so as not to block other
70 // threads in contention for the lock if UpdateItems blocks.
71 Log<UniverseManager>.Debug ("Reloading item source \"{0}\"...", safeSource.Name);
72 safeSource.UpdateItems ();
73 newItems = safeSource.Items;
74
75- lock (universe) {
76- foreach (Item item in oldItems) {
77- if (universe.ContainsKey (item.UniqueId))
78- universe.Remove (item.UniqueId);
79- }
80+ lock (universe_lock) {
81 foreach (Item item in newItems) {
82 universe [item.UniqueId] = item;
83 }
84@@ -229,6 +222,8 @@
85 void ReloadUniverse ()
86 {
87 Log<UniverseManager>.Info ("Reloading universe...");
88+ lock (universe_lock)
89+ universe.Clear ();
90 ReloadActions ();
91 PluginManager.ItemSources.ForEach (ReloadSource);
92 Log<UniverseManager>.Info ("Universe contains {0} items.", universe.Count);
93@@ -242,7 +237,7 @@
94 /// </param>
95 public void AddItems (IEnumerable<Item> items)
96 {
97- lock (universe) {
98+ lock (universe_lock) {
99 foreach (Item item in items) {
100 if (universe.ContainsKey (item.UniqueId)) continue;
101 universe [item.UniqueId] = item;
102@@ -259,7 +254,7 @@
103 /// </param>
104 public void DeleteItems (IEnumerable<Item> items)
105 {
106- lock (universe) {
107+ lock (universe_lock) {
108 foreach (Item item in items) {
109 universe.Remove (item.UniqueId);
110 }
111@@ -277,7 +272,7 @@
112 /// </param>
113 public bool TryGetItemForUniqueId (string uid, out Item element)
114 {
115- lock (universe) {
116+ lock (universe_lock) {
117 if (universe.ContainsKey (uid)) {
118 element = universe [uid];
119 } else {