Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yield timeslice when waiting for auth_query #545

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sources/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ int od_hashmap_insert(od_hashmap_t *hm, od_hash_t keyhash,
ret = 0;
} else {
/* oom or other error */
pthread_mutex_unlock(&hm->buckets[bucket_index]->mu);
return -1;
}
} else {
Expand Down Expand Up @@ -217,7 +218,13 @@ od_hashmap_elt_t *od_hashmap_lock_key(od_hashmap_t *hm, od_hash_t keyhash,
od_hashmap_elt_t *key)
{
size_t bucket_index = keyhash % hm->size;
pthread_mutex_lock(&hm->buckets[bucket_index]->mu);
/*
* This function is used to aquire long locks in auth_query.
* To avoid intra-machine locks we must yield cpu slice from time to time
* even if waiting for other lock.
*/
while (!pthread_mutex_trylock(&hm->buckets[bucket_index]->mu))
machine_sleep(1);

od_hashmap_elt_t *ptr = od_bucket_search(hm->buckets[bucket_index],
key->data, key->len);
Expand Down
6 changes: 2 additions & 4 deletions sources/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,7 @@ int od_rules_validate(od_rules_t *rules, od_config_t *config,
{
/* storages */
if (od_list_empty(&rules->storages)) {
od_error(logger, "rules", NULL, NULL,
"no storage defined");
od_error(logger, "rules", NULL, NULL, "no storage defined");
return -1;
}

Expand Down Expand Up @@ -980,8 +979,7 @@ int od_rules_validate(od_rules_t *rules, od_config_t *config,

/* rules */
if (od_list_empty(&rules->rules)) {
od_error(logger, "rules", NULL, NULL,
"no rules defined");
od_error(logger, "rules", NULL, NULL, "no rules defined");
return -1;
}

Expand Down
Loading