[f-spot/mipmapped-loading: 13/13] Immediately run continuation on same task if only one set.



commit 75eb4f9e94c53bf1f6c0fe72f420e3524f32bf84
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Jul 2 16:28:10 2010 +0200

    Immediately run continuation on same task if only one set.

 src/GroupSelector.cs          |    3 +++
 src/Tasks/Task.cs             |   18 ++++++++++--------
 src/Tasks/WorkerThreadTask.cs |    4 ++--
 3 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/GroupSelector.cs b/src/GroupSelector.cs
index 6bd0d62..f7d0890 100644
--- a/src/GroupSelector.cs
+++ b/src/GroupSelector.cs
@@ -4,6 +4,7 @@ using Gtk;
 using Gdk;
 using GLib;
 using FSpot.Utils;
+using Hyena;
 
 namespace FSpot {
 	public class GroupSelector : Fixed {
@@ -292,6 +293,8 @@ namespace FSpot {
 
 		protected override bool OnButtonPressEvent (Gdk.EventButton args)
 		{
+			ThreadAssist.AssertInMainThread ();
+
 			if (args.Button == 3)
 				return DrawOrderMenu (args); 
 
diff --git a/src/Tasks/Task.cs b/src/Tasks/Task.cs
index 6c390e9..116192f 100644
--- a/src/Tasks/Task.cs
+++ b/src/Tasks/Task.cs
@@ -188,24 +188,26 @@ namespace FSpot.Tasks
 
 		public void Execute ()
 		{
-			if (State != TaskState.Scheduled && State != TaskState.Cancelled)
-				throw new Exception ("Can't start task manually!");
-
-			if (State == TaskState.Cancelled || State == TaskState.Completed)
+			if (State == TaskState.Cancelled || State == TaskState.Completed) {
 				return;
+			}
 
 			try {
 				result = Handler ();
 				State = TaskState.Completed;
+				WaitEvent.Set ();
 
-				foreach (var child in Children) {
-					(child as ISchedulable).Schedule ();
+				if (Children.Count == 1) {
+					Children [0].Execute ();
+				} else {
+					foreach (var child in Children) {
+						(child as ISchedulable).Schedule ();
+					}
 				}
 			} catch (Exception e) {
 				State = TaskState.Exception;
-				throw e;
-			} finally {
 				WaitEvent.Set ();
+				throw e;
 			}
 		}
 
diff --git a/src/Tasks/WorkerThreadTask.cs b/src/Tasks/WorkerThreadTask.cs
index bb22922..b216b7e 100644
--- a/src/Tasks/WorkerThreadTask.cs
+++ b/src/Tasks/WorkerThreadTask.cs
@@ -86,7 +86,6 @@ namespace FSpot.Tasks
 		internal WorkerThreadTaskScheduler (bool start_worker)
 		{
 			max_tasks = Environment.ProcessorCount * 2;
-			Log.DebugFormat ("Doing at most {0} tasks", max_tasks);
 
 			// Not starting the worker means that the scheduler won't work,
 			// but this can be useful for unit tests.
@@ -117,13 +116,14 @@ namespace FSpot.Tasks
 						continue;
 				}
 
+#pragma warning disable 0420 // ref vars are not volatile, unless with interlocked, so safe to silence.
 				Interlocked.Increment (ref tasks_queued);
 				ThreadPool.QueueUserWorkItem ((o) => {
 					task.Execute ();
-					Log.DebugFormat ("Finished task {0}", task);
 					Interlocked.Decrement (ref tasks_queued);
 					wait.Set ();
 				});
+#pragma warning restore 0420
 			}
 		}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]