]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix race conditions in _epggrab_ota_finished() and epggrab_mux_next()
authorRichard Kunze <richard.kunze@web.de>
Tue, 25 Sep 2012 22:37:41 +0000 (00:37 +0200)
committerAdam Sutton <dev@adamsutton.me.uk>
Fri, 8 Mar 2013 22:23:02 +0000 (22:23 +0000)
(cherry picked from commit dc75437202d71b79af3b4c85c4d2f6983000d212)

src/epggrab/otamux.c

index c424207975f4f82867d5f32fb7ca3ecbf685624e..3669664cfcdc8e0a0e69fde3f666cb972c9a404b 100644 (file)
@@ -89,9 +89,10 @@ th_dvb_mux_instance_t *epggrab_mux_next ( th_dvb_adapter_t *tda )
   epggrab_ota_mux_t *ota;
   time(&now);
   TAILQ_FOREACH(ota, &ota_mux_all, glob_link) {
+    if (ota->tdmi->tdmi_adapter != tda) continue;
     if (ota->interval + ota->completed > now) return NULL;
     if (!ota->is_reg) return NULL;
-    if (ota->tdmi->tdmi_adapter == tda) break;
+    break;
   }
   return ota ? ota->tdmi : NULL;
 }
@@ -337,7 +338,21 @@ static void _epggrab_ota_finished ( epggrab_ota_mux_t *ota )
   /* Reinsert into reg queue */
   else {
     TAILQ_REMOVE(&ota_mux_all, ota, glob_link);
-    TAILQ_INSERT_SORTED(&ota_mux_all, ota, glob_link, _ota_time_cmp);
+    // Find the last queue entry that can run before ota
+    // (i.e _ota_time_cmp(ota, entry)>0) and re-insert ota
+    // directly after this entry. If no matching entry is
+    // found (i.e ota can run before any other entry),
+    // re-insert ota at the queue head.
+    epggrab_ota_mux_t *entry = NULL;
+    epggrab_ota_mux_t *tmp;
+    TAILQ_FOREACH(tmp, &ota_mux_all, glob_link) {
+      if(_ota_time_cmp(ota, tmp)>0) entry = tmp;
+    }
+    if (entry) {
+      TAILQ_INSERT_AFTER(&ota_mux_all, entry, ota, glob_link);
+    } else {
+      TAILQ_INSERT_HEAD(&ota_mux_all, ota, glob_link);
+    }
   }
 }