From: Jaroslav Kysela Date: Tue, 3 May 2016 20:01:52 +0000 (+0200) Subject: api idnode: do not hold one global lock for multiple entries, fixes #3773 X-Git-Tag: v4.2.1~592 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9ec7344673b25f35f9816349435b6c8fc685f3e;p=thirdparty%2Ftvheadend.git api idnode: do not hold one global lock for multiple entries, fixes #3773 --- diff --git a/src/api/api_idnode.c b/src/api/api_idnode.c index 6bfbbd82a..7883bf508 100644 --- a/src/api/api_idnode.c +++ b/src/api/api_idnode.c @@ -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; }