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

Function hash_init_flags

lib/hash.c:45–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45gen_hash_t *hash_init_flags(unsigned int size, unsigned int flags)
46{
47 unsigned int n;
48 gen_hash_t *h;
49
50 /* initialized the hash table */
51 for (n=0 ; n<(8*sizeof(n) - 1) ; n++) {
52 if (size==(1<<n))
53 break;
54 if (size<(1<<n)) {
55 LM_WARN("hash_size is not a power "
56 "of 2 as it should be -> rounding from %d to %d\n",
57 size, 1<<(n-1));
58 size = 1<<(n-1);
59 break;
60 }
61 }
62
63 if (flags & HASH_MAP_PERSIST)
64 h = rpm_malloc(sizeof *h + size * sizeof(*h->entries));
65 else
66 h = shm_malloc(sizeof *h + size * sizeof(*h->entries));
67 if (!h) {
68 LM_ERR("could not alloc hash of %d elements!\n", size);
69 return NULL;
70 }
71 memset(h, 0, sizeof *h + size * sizeof(*h->entries));
72 h->entries = (map_t *)(h + 1);
73 h->size = size;
74 h->flags = flags;
75 if (hash_init_locks(h) < 0) {
76 LM_ERR("could not alloc locks for hash!\n");
77 goto error;
78 }
79
80 for (n = 0; n < h->size; n++) {
81 h->entries[n] = map_create(
82 ((flags&HASH_MAP_PERSIST)?AVLMAP_PERSISTENT:AVLMAP_SHARED));
83 if (!h->entries[n]) {
84 h->size = n; /* we only account for what we've already created */
85 goto error;
86 }
87 }
88 return h;
89error:
90 hash_destroy(h, NULL);
91 return NULL;
92}
93
94void hash_destroy_locks(gen_hash_t *hash)
95{

Callers 1

config_new_cacheFunction · 0.85

Calls 5

rpm_mallocFunction · 0.85
shm_mallocFunction · 0.85
hash_init_locksFunction · 0.85
map_createFunction · 0.85
hash_destroyFunction · 0.85

Tested by

no test coverage detected