Skip to content

Commit

Permalink
sources/hashmap.c: fix lock (#706)
Browse files Browse the repository at this point in the history
pthread_mutex_trylock returns non-zero, when mutex is not locked,
so current usage will sleep when mutex is locked succesfully

Signed-off-by: rkhapov <r.khapov@ya.ru>
Co-authored-by: rkhapov <r.khapov@ya.ru>
  • Loading branch information
rkhapov and rkhapov authored Oct 28, 2024
1 parent 81c16a5 commit f5d29e6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sources/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ od_hashmap_elt_t *od_hashmap_lock_key(od_hashmap_t *hm, od_hash_t keyhash,
* 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))
while (pthread_mutex_trylock(&hm->buckets[bucket_index]->mu))
machine_sleep(1);

od_hashmap_elt_t *ptr = od_bucket_search(hm->buckets[bucket_index],
Expand Down

0 comments on commit f5d29e6

Please sign in to comment.