Forráskód Böngészése

Allow specification of number of workers

Billy Barrow 1 hónapja
szülő
commit
9c06d09562
1 módosított fájl, 15 hozzáadás és 3 törlés
  1. 15 3
      src/Application.vala

+ 15 - 3
src/Application.vala

@@ -3,18 +3,29 @@ namespace Webmify {
     static string watch_dir;
     static string output_dir;
     static string work_dir;
+    static uint workers;
     static Invercargill.Set<string> processed_files;
     static Invercargill.Fifo<string> queue;
 
     public static int main(string[] argv) {
-        if(argv.length != 4) {
-            printerr(@"Usage:\n$(argv[0]) watch_dir output_dir work_dir\n");
+        if(argv.length != 4 && argv.length != 5) {
+            printerr(@"Usage:\n$(argv[0]) watch_dir output_dir work_dir [workers]\n");
             return -1;
         }
 
         watch_dir = argv[1];
         output_dir = argv[2];
         work_dir = argv[3];
+
+        workers = get_num_processors();
+        if(argv.length == 5){
+            workers = uint.parse(argv[4]);
+        }
+        if(workers < 1) {
+            printerr("Invalid number of workers\n");
+            return -2;
+        }
+
         processed_files = new Invercargill.Set<string>();
         queue = new Invercargill.Fifo<string>();
 
@@ -22,6 +33,7 @@ namespace Webmify {
         new Thread<bool>("watcher", watch_directory);
 
         // Create the workers
+        print(@"Creating $workers workers.\n");
         queue.parallel_iterate(path => {
             var filename = Path.get_basename(path);
             print(@"Dequeue \"$filename\"\n");
@@ -52,7 +64,7 @@ namespace Webmify {
             output_path.delete();
             video_file.delete();
             print(@"Conversion complete: $filename -> $(Path.get_basename(output_path.get_path()))\n");
-        });
+        }, workers);
 
         assert_not_reached();
         return 0;