]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
api idnode: do not hold one global lock for multiple entries, fixes #3773
authorJaroslav Kysela <perex@perex.cz>
Tue, 3 May 2016 20:01:52 +0000 (22:01 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 3 May 2016 20:02:42 +0000 (22:02 +0200)
src/api/api_idnode.c

index 6bfbbd82a9703158cc2c49b5c6a64498146c6384..7883bf5089d38104eea6caef6682678891f8bf23 100644 (file)
@@ -638,16 +638,21 @@ api_idnode_handler
     htsmsg_add_str(msg, "__op__", op);
     HTSMSG_FOREACH(f, uuids) {
       if (!(uuid = htsmsg_field_get_string(f))) continue;
-      if (!(in   = idnode_find(uuid, NULL, domain))) continue;
-      domain = in->in_domain;
-      if (idnode_perm(in, perm, msg)) {
-        pcnt++;
-        continue;
+      pthread_mutex_lock(&global_lock);
+      if ((in = idnode_find(uuid, NULL, domain)) != NULL) {
+        domain = in->in_domain;
+        if (idnode_perm(in, perm, msg)) {
+          pcnt++;
+          continue;
+        }
+        handler(perm, in);
+        if (!destroyed)
+          idnode_perm_unset(in);
+        cnt++;
       }
-      handler(perm, in);
-      if (!destroyed)
-        idnode_perm_unset(in);
-      cnt++;
+      pthread_mutex_unlock(&global_lock);
+      if (destroyed)
+        pthread_yield(); /* delete penalty */
     }
     htsmsg_destroy(msg);
 
@@ -657,6 +662,7 @@ api_idnode_handler
   /* Single */
   } else {
     uuid = htsmsg_field_get_string(f);
+    pthread_mutex_lock(&global_lock);
     if (!(in   = idnode_find(uuid, NULL, NULL))) {
       err = ENOENT;
     } else {
@@ -670,9 +676,9 @@ api_idnode_handler
       }
       htsmsg_destroy(msg);
     }
+    pthread_mutex_unlock(&global_lock);
   }
 
-  pthread_mutex_unlock(&global_lock);
 
   return err;
 }