[baobab/wip/vala: 18/41] threaded scanner: use an asyncqueue



commit a552d528164b8b9e970aa268f1b772248fdaebfc
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 5 19:36:05 2012 -0500

    threaded scanner: use an asyncqueue
    
    instead of using a GQueue and separate mutex

 src/baobab-threaded-scanner.vala |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)
---
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index 15fa36f..a1b23cc 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -1,8 +1,7 @@
 namespace Baobab {
 	class ThreadedScanner : Scanner {
-		Queue<ResultsArray> results_queue;
+		AsyncQueue<ResultsArray> results_queue;
 		ThreadedScanner? self;
-		Mutex mutex;
 
 		File directory;
 
@@ -111,9 +110,7 @@ namespace Baobab {
 				child_results.percent = 100 * ((double) child_results.size) / ((double) results.size);
 			}
 
-			mutex.lock ();
-			results_queue.push_tail ((owned) results_array);
-			mutex.unlock ();
+			results_queue.push ((owned) results_array);
 
 			return results;
 		}
@@ -158,9 +155,7 @@ namespace Baobab {
 
 		bool process_results () {
 			while (true) {
-				mutex.lock ();
-				var results_array = results_queue.pop_head ();
-				mutex.unlock ();
+				var results_array = results_queue.try_pop ();
 
 				if (results_array == null) {
 					break;
@@ -201,8 +196,7 @@ namespace Baobab {
 		}
 
 		public ThreadedScanner () {
-			results_queue = new Queue<ResultsArray> ();
-			mutex = new Mutex ();
+			results_queue = new AsyncQueue<ResultsArray> ();
 		}
 	}
 }



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