Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
api idnode: do not hold one global lock for multiple entries, fixes #…
…3773
  • Loading branch information
perexg committed May 3, 2016
1 parent d8a32f0 commit f9ec734
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/api/api_idnode.c
Expand Up @@ -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);

Expand All @@ -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 {
Expand All @@ -670,9 +676,9 @@ api_idnode_handler
}
htsmsg_destroy(msg);
}
pthread_mutex_unlock(&global_lock);
}

pthread_mutex_unlock(&global_lock);

return err;
}
Expand Down

0 comments on commit f9ec734

Please sign in to comment.