| 31 | #include "../../locking.h" |
| 32 | |
| 33 | int init_hash_map(hash_map_t *hm) |
| 34 | { |
| 35 | unsigned int i; |
| 36 | |
| 37 | hm->buckets = shm_malloc(hm->size * sizeof(hash_bucket_t)); |
| 38 | if (hm->buckets == NULL) { |
| 39 | LM_ERR("No more shm memory\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | for (i = 0; i < hm->size; ++i) { |
| 44 | hm->buckets[i].items = map_create(AVLMAP_SHARED); |
| 45 | if (!hm->buckets[i].items) { |
| 46 | LM_ERR("oom\n"); |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | hm->buckets[i].lock = lock_alloc(); |
| 51 | if (!hm->buckets[i].lock) { |
| 52 | LM_ERR("cannot init lock\n"); |
| 53 | shm_free(hm->buckets); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | if (!lock_init(hm->buckets[i].lock)) { |
| 58 | lock_dealloc(hm->buckets[i].lock); |
| 59 | shm_free(hm->buckets); |
| 60 | LM_ERR("faled to init lock\n"); |
| 61 | return -1; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void free_hash_map(hash_map_t* hm, void (*value_destroy_func)(void *)) |
| 69 | { |
no test coverage detected