]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epggrab: XMLTV / PyXML - don't use one global lock for whole input
authorJaroslav Kysela <perex@perex.cz>
Fri, 23 Oct 2015 12:25:23 +0000 (14:25 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 23 Oct 2015 12:26:18 +0000 (14:26 +0200)
src/epg.c
src/epggrab/module.c
src/epggrab/module/pyepg.c
src/epggrab/module/xmltv.c

index e25116270d60972ebe58ce890791774d2f655275..aae95c023b12b12146f1f9c6a7e7960604345218 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -117,6 +117,8 @@ void epg_updated ( void )
 {
   epg_object_t *eo;
 
+  lock_assert(&global_lock);
+
   /* Remove unref'd */
   while ((eo = LIST_FIRST(&epg_object_unref))) {
     tvhtrace("epg",
index d662d2a4c07c7cf20c5c7a90fad246166f8904f2..d3b46e8814b97d99193e2c84ee5cedb20cb8a429 100644 (file)
@@ -227,12 +227,9 @@ void epggrab_module_parse( void *m, htsmsg_t *data )
 
   /* Parse */
   memset(&stats, 0, sizeof(stats));
-  pthread_mutex_lock(&global_lock);
   time(&tm1);
   save |= mod->parse(mod, data, &stats);
   time(&tm2);
-  if (save) epg_updated();  
-  pthread_mutex_unlock(&global_lock);
   htsmsg_destroy(data);
 
   /* Debug stats */
index 4834fc75a20ae0c6830e39b32b925675bb4ebe53..9fddbd5eb3586e8c90b3bef3e20f64347b317fbb 100644 (file)
@@ -377,27 +377,43 @@ static int _pyepg_parse_schedule
 static int _pyepg_parse_epg 
   ( epggrab_module_t *mod, htsmsg_t *data, epggrab_stats_t *stats )
 {
-  int save = 0;
+  int gsave = 0, save;
   htsmsg_t *tags;
   htsmsg_field_t *f;
 
   if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0;
 
   HTSMSG_FOREACH(f, tags) {
+    save = 0;
     if (strcmp(f->hmf_name, "channel") == 0 ) {
-      save |= _pyepg_parse_channel(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _pyepg_parse_channel(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_unlock(&global_lock);
     } else if (strcmp(f->hmf_name, "brand") == 0 ) {
-      save |= _pyepg_parse_brand(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _pyepg_parse_brand(mod, htsmsg_get_map_by_field(f), stats);
+      if (save) epg_updated();
+      pthread_mutex_unlock(&global_lock);
     } else if (strcmp(f->hmf_name, "series") == 0 ) {
-      save |= _pyepg_parse_season(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _pyepg_parse_season(mod, htsmsg_get_map_by_field(f), stats);
+      if (save) epg_updated();
+      pthread_mutex_unlock(&global_lock);
     } else if (strcmp(f->hmf_name, "episode") == 0 ) {
-      save |= _pyepg_parse_episode(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _pyepg_parse_episode(mod, htsmsg_get_map_by_field(f), stats);
+      if (save) epg_updated();
+      pthread_mutex_unlock(&global_lock);
     } else if (strcmp(f->hmf_name, "schedule") == 0 ) {
-      save |= _pyepg_parse_schedule(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _pyepg_parse_schedule(mod, htsmsg_get_map_by_field(f), stats);
+      if (save) epg_updated();
+      pthread_mutex_unlock(&global_lock);
     }
+    gsave |= save;
   }
 
-  return save;
+  return gsave;
 }
 
 static int _pyepg_parse 
index 2c300c402d73eaf73e6710df96fd95d30775c9c0..8286e95df4a6528f8198041d84258631e7f251a8 100644 (file)
@@ -654,7 +654,7 @@ static int _xmltv_parse_channel
 static int _xmltv_parse_tv
   (epggrab_module_t *mod, htsmsg_t *body, epggrab_stats_t *stats)
 {
-  int save = 0;
+  int gsave = 0, save;
   htsmsg_t *tags;
   htsmsg_field_t *f;
 
@@ -662,13 +662,20 @@ static int _xmltv_parse_tv
     return 0;
 
   HTSMSG_FOREACH(f, tags) {
+    save = 0;
     if(!strcmp(f->hmf_name, "channel")) {
-      save |= _xmltv_parse_channel(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _xmltv_parse_channel(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_unlock(&global_lock);
     } else if(!strcmp(f->hmf_name, "programme")) {
-      save |= _xmltv_parse_programme(mod, htsmsg_get_map_by_field(f), stats);
+      pthread_mutex_lock(&global_lock);
+      save = _xmltv_parse_programme(mod, htsmsg_get_map_by_field(f), stats);
+      if (save) epg_updated();
+      pthread_mutex_unlock(&global_lock);
     }
+    gsave |= save;
   }
-  return save;
+  return gsave;
 }
 
 static int _xmltv_parse