Skip to content

Commit

Permalink
Yield timeslice when waiting for auth_query (#545)
Browse files Browse the repository at this point in the history
* Yield timeslice when waiting for auth_query

* Formatting
  • Loading branch information
x4m authored Nov 20, 2023
1 parent e2e3ee6 commit be08883
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit be08883

Please sign in to comment.