MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / init_hash_map

Function init_hash_map

modules/fraud_detection/frd_hashmap.c:33–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#include "../../locking.h"
32
33int 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
68void free_hash_map(hash_map_t* hm, void (*value_destroy_func)(void *))
69{

Callers 2

init_stats_tableFunction · 0.85
get_statsFunction · 0.85

Calls 4

shm_mallocFunction · 0.85
map_createFunction · 0.85
shm_freeFunction · 0.85
lock_initFunction · 0.85

Tested by

no test coverage detected