|
@@ -8,6 +8,7 @@
|
|
|
|
|
|
static gen_lock_t *rtpengine_hash_lock;
|
|
static gen_lock_t *rtpengine_hash_lock;
|
|
static struct rtpengine_hash_table *rtpengine_hash_table;
|
|
static struct rtpengine_hash_table *rtpengine_hash_table;
|
|
|
|
+static int hash_table_size;
|
|
|
|
|
|
/* from sipwise rtpengine */
|
|
/* from sipwise rtpengine */
|
|
static int str_cmp_str(const str *a, const str *b) {
|
|
static int str_cmp_str(const str *a, const str *b) {
|
|
@@ -37,13 +38,21 @@ static unsigned int str_hash(void *ss) {
|
|
it.len--;
|
|
it.len--;
|
|
}
|
|
}
|
|
|
|
|
|
- return ret % RTPENGINE_HASH_TABLE_SIZE;
|
|
|
|
|
|
+ return ret % hash_table_size;
|
|
}
|
|
}
|
|
|
|
|
|
/* rtpengine glib hash API */
|
|
/* rtpengine glib hash API */
|
|
-int rtpengine_hash_table_init() {
|
|
|
|
|
|
+int rtpengine_hash_table_init(int size) {
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
+ // init hash table size
|
|
|
|
+ if (size < 1) {
|
|
|
|
+ hash_table_size = 1;
|
|
|
|
+ } else {
|
|
|
|
+ hash_table_size = size;
|
|
|
|
+ }
|
|
|
|
+ LM_DBG("rtpengine_hash_table size = %d\n", hash_table_size);
|
|
|
|
+
|
|
// init hashtable
|
|
// init hashtable
|
|
rtpengine_hash_table = shm_malloc(sizeof(struct rtpengine_hash_table));
|
|
rtpengine_hash_table = shm_malloc(sizeof(struct rtpengine_hash_table));
|
|
if (!rtpengine_hash_table) {
|
|
if (!rtpengine_hash_table) {
|
|
@@ -51,15 +60,18 @@ int rtpengine_hash_table_init() {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- // init hashtable entry_list heads (never filled)
|
|
|
|
- for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
|
|
|
|
|
|
+ // init hashtable entry_list
|
|
|
|
+ rtpengine_hash_table->entry_list = shm_malloc(hash_table_size * sizeof(struct rtpengine_hash_entry));
|
|
|
|
+
|
|
|
|
+ // init hashtable entry_list[i] (head never filled)
|
|
|
|
+ for (i = 0; i < hash_table_size; i++) {
|
|
rtpengine_hash_table->entry_list[i] = shm_malloc(sizeof(struct rtpengine_hash_entry));
|
|
rtpengine_hash_table->entry_list[i] = shm_malloc(sizeof(struct rtpengine_hash_entry));
|
|
if (!rtpengine_hash_table->entry_list[i]) {
|
|
if (!rtpengine_hash_table->entry_list[i]) {
|
|
LM_ERR("no shm left to create rtpengine_hash_table->entry_list[%d]\n", i);
|
|
LM_ERR("no shm left to create rtpengine_hash_table->entry_list[%d]\n", i);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- /* never expire the head of the hashtable index lists */
|
|
|
|
|
|
+ // never expire the head of the hashtable index lists
|
|
rtpengine_hash_table->entry_list[i]->tout = -1;
|
|
rtpengine_hash_table->entry_list[i]->tout = -1;
|
|
rtpengine_hash_table->entry_list[i]->next = NULL;
|
|
rtpengine_hash_table->entry_list[i]->next = NULL;
|
|
}
|
|
}
|
|
@@ -84,9 +96,9 @@ int rtpengine_hash_table_destroy() {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- // destroy hashtable entry_list content
|
|
|
|
|
|
+ // destroy hashtable entry_list[i]
|
|
lock_get(rtpengine_hash_lock);
|
|
lock_get(rtpengine_hash_lock);
|
|
- for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
|
|
|
|
|
|
+ for (i = 0; i < hash_table_size; i++) {
|
|
entry = rtpengine_hash_table->entry_list[i];
|
|
entry = rtpengine_hash_table->entry_list[i];
|
|
while (entry) {
|
|
while (entry) {
|
|
last_entry = entry;
|
|
last_entry = entry;
|
|
@@ -96,6 +108,9 @@ int rtpengine_hash_table_destroy() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // destroy hashtable entry_list
|
|
|
|
+ shm_free(rtpengine_hash_table->entry_list);
|
|
|
|
+
|
|
// destroy hashtable
|
|
// destroy hashtable
|
|
shm_free(rtpengine_hash_table);
|
|
shm_free(rtpengine_hash_table);
|
|
rtpengine_hash_table = NULL;
|
|
rtpengine_hash_table = NULL;
|
|
@@ -283,7 +298,7 @@ void rtpengine_hash_table_print() {
|
|
lock_get(rtpengine_hash_lock);
|
|
lock_get(rtpengine_hash_lock);
|
|
|
|
|
|
// print hashtable
|
|
// print hashtable
|
|
- for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
|
|
|
|
|
|
+ for (i = 0; i < hash_table_size; i++) {
|
|
entry = rtpengine_hash_table->entry_list[i];
|
|
entry = rtpengine_hash_table->entry_list[i];
|
|
last_entry = entry;
|
|
last_entry = entry;
|
|
|
|
|