Making the option -N work fine; jobs get into running if there are free slots. jobslots
authorviric <viriketo@gmail.com>
Sat, 26 May 2012 16:03:35 +0200
branchjobslots
changeset 316 7ce3aeaf73b5
parent 315 2b3ed8fdfb12
child 317 290b5aa53061
Making the option -N work fine; jobs get into running if there are free slots.
jobs.c
main.c
--- a/jobs.c	Wed May 23 19:38:12 2012 +0200
+++ b/jobs.c	Sat May 26 16:03:35 2012 +0200
@@ -502,10 +502,12 @@
 {
     struct Job *p;
 
+    const int free_slots = max_slots - busy_slots;
+
     /* busy_slots may be bigger than the maximum slots,
      * if the user was running many jobs, and suddenly
      * trimmed the maximum slots down. */
-    if (busy_slots >= max_slots)
+    if (free_slots <= 0)
         return -1;
 
     /* If there are no jobs to run... */
@@ -532,8 +534,11 @@
                 }
             }
 
-            ++busy_slots;
-            return p->jobid;
+            if (free_slots >= p->num_slots)
+            {
+                busy_slots = busy_slots + p->num_slots;
+                return p->jobid;
+            }
         }
         p = p->next;
     }
@@ -632,7 +637,7 @@
      * we call this to clean up the jobs list in case of the client closing the
      * connection. */
     if (p->state == RUNNING)
-        --busy_slots;
+        busy_slots = busy_slots - p->num_slots;
 
     /* Mark state */
     if (result->skipped)
--- a/main.c	Wed May 23 19:38:12 2012 +0200
+++ b/main.c	Sat May 26 16:03:35 2012 +0200
@@ -84,7 +84,7 @@
 
     /* Parse options */
     while(1) {
-        c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:u:s:U:i:L:dS:D:");
+        c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:u:s:U:i:N:L:dS:D:");
 
         if (c == -1)
             break;