]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
service subscription: improve the input selection in busy condition
authorJaroslav Kysela <perex@perex.cz>
Fri, 26 Feb 2016 20:15:23 +0000 (21:15 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 26 Feb 2016 20:15:23 +0000 (21:15 +0100)
src/service.c

index c96a956fbb50cb1efb6c665bea681f062ba8b83d..8fdc694cec8bc5c5e1d7cfaf4f388567c6f79dbd 100644 (file)
@@ -697,7 +697,7 @@ service_find_instance
   idnode_list_mapping_t *ilm;
   service_instance_t *si, *next;
   profile_t *pro = prch ? prch->prch_pro : NULL;
-  int enlisted, weight2;
+  int enlisted;
 
   lock_assert(&global_lock);
 
@@ -775,15 +775,20 @@ service_find_instance
         break;
   }
 
-  /* Bump the one with lowest weight */
+  /* Bump the one with lowest weight or bigger priority */
   if (!si) {
     next = NULL;
-    weight2 = weight;
-    TAILQ_FOREACH(si, sil, si_link)
-      if (weight2 > si->si_weight && si->si_error == 0) {
-        weight2 = si->si_weight;
-        next = si;
+    TAILQ_FOREACH(si, sil, si_link) {
+      if (si->si_error) continue;
+      if (next == NULL) {
+        if (si->si_weight < weight)
+          next = si;
+      } else {
+        if ((si->si_weight < next->si_weight) ||
+            (si->si_weight == next->si_weight && si->si_prio > next->si_prio))
+          next = si;
       }
+    }
     si = next;
   }