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 <[email protected]>
Co-authored-by: rkhapov <[email protected]>
(cherry picked from commit f5d29e6)
Signed-off-by: rkhapov <[email protected]>
  • Loading branch information
rkhapov and rkhapov committed Oct 28, 2024
1 parent d578225 commit 04810ab
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 04810ab

Please sign in to comment.