diff --git a/sources/hashmap.c b/sources/hashmap.c index 60c633ce1..9db6fbba9 100644 --- a/sources/hashmap.c +++ b/sources/hashmap.c @@ -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 { @@ -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); diff --git a/sources/rules.c b/sources/rules.c index 1a55fc013..ad89a692d 100644 --- a/sources/rules.c +++ b/sources/rules.c @@ -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; } @@ -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; }