Browse code

rtp_media_server: fix dialog_list_mutex

issue 2522

(cherry picked from commit 750cb7fc131afa254952536bdb200d55e2cc8955)

Julien Chavanton authored on 23/10/2020 20:21:45 • Daniel-Constantin Mierla committed on 26/10/2020 09:59:35
Showing 4 changed files
... ...
@@ -23,7 +23,7 @@
23 23
 extern rms_dialog_info_t *rms_dialog_list;
24 24
 extern int in_rms_process;
25 25
 
26
-gen_lock_t dialog_list_mutex;
26
+gen_lock_t *dialog_list_mutex;
27 27
 
28 28
 static void rms_action_free(rms_dialog_info_t *si)
29 29
 {
... ...
@@ -48,8 +48,12 @@ rms_action_t *rms_action_new(rms_action_type_t t)
48 48
 	return a;
49 49
 }
50 50
 
51
-int init_rms_dialog_list()
51
+int rms_dialog_list_init()
52 52
 {
53
+	dialog_list_mutex = lock_alloc();
54
+	if(!dialog_list_mutex)
55
+		return 0;
56
+	dialog_list_mutex = lock_init(dialog_list_mutex);
53 57
 	rms_dialog_list = shm_malloc(sizeof(rms_dialog_info_t));
54 58
 	if(!rms_dialog_list)
55 59
 		return 0;
... ...
@@ -57,6 +61,13 @@ int init_rms_dialog_list()
57 61
 	return 1;
58 62
 }
59 63
 
64
+void rms_dialog_list_free()
65
+{
66
+	lock_destroy(dialog_list_mutex);
67
+	lock_dealloc((void*)dialog_list_mutex);
68
+	shm_free(rms_dialog_list);
69
+}
70
+
60 71
 rms_dialog_info_t *rms_dialog_search(struct sip_msg *msg) // str *from_tag)
61 72
 {
62 73
 	rms_dialog_info_t *si;
... ...
@@ -90,9 +101,9 @@ rms_dialog_info_t *rms_dialog_search(struct sip_msg *msg) // str *from_tag)
90 101
 
91 102
 rms_dialog_info_t *rms_dialog_search_sync(struct sip_msg *msg)
92 103
 {
93
-	lock(&dialog_list_mutex);
104
+	lock(dialog_list_mutex);
94 105
 	rms_dialog_info_t *si = rms_dialog_search(msg);
95
-	unlock(&dialog_list_mutex);
106
+	unlock(dialog_list_mutex);
96 107
 	return si;
97 108
 }
98 109
 
... ...
@@ -101,9 +112,9 @@ void rms_dialog_add(rms_dialog_info_t *si)
101 112
 	if (in_rms_process) {
102 113
 		clist_append(rms_dialog_list, si, next, prev);
103 114
 	} else {
104
-		lock(&dialog_list_mutex);
115
+		lock(dialog_list_mutex);
105 116
 		clist_append(rms_dialog_list, si, next, prev);
106
-		unlock(&dialog_list_mutex);
117
+		unlock(dialog_list_mutex);
107 118
 	}
108 119
 }
109 120
 
... ...
@@ -112,9 +123,9 @@ void rms_dialog_rm(rms_dialog_info_t *si)
112 123
 	if (in_rms_process) {
113 124
 		clist_append(rms_dialog_list, si, next, prev);
114 125
 	} else {
115
-		lock(&dialog_list_mutex);
126
+		lock(dialog_list_mutex);
116 127
 		clist_rm(si, next, prev);
117
-		unlock(&dialog_list_mutex);
128
+		unlock(dialog_list_mutex);
118 129
 	}
119 130
 }
120 131
 
... ...
@@ -58,7 +58,8 @@ typedef struct rms_action
58 58
 
59 59
 int rms_check_msg(struct sip_msg *msg);
60 60
 rms_action_t *rms_action_new(rms_action_type_t t);
61
-int init_rms_dialog_list();
61
+int rms_dialog_list_init();
62
+void rms_dialog_list_free();
62 63
 rms_dialog_info_t *rms_dialog_search(struct sip_msg *msg);
63 64
 rms_dialog_info_t *rms_dialog_search_sync(struct sip_msg *msg);
64 65
 void rms_dialog_add(rms_dialog_info_t *di);
... ...
@@ -175,7 +175,7 @@ static int mod_init(void)
175 175
 	rms->udp_last_port = 50000 + kam_rand() % 10000;
176 176
 	rms_media_init();
177 177
 
178
-	if(!init_rms_dialog_list()) {
178
+	if(!rms_dialog_list_init()) {
179 179
 		LM_ERR("can't initialize rms_dialog_list !\n");
180 180
 		return -1;
181 181
 	}
... ...
@@ -314,14 +314,14 @@ static void rms_dialog_manage_loop()
314 314
 {
315 315
 	in_rms_process = 1;
316 316
 	while(1) {
317
-		lock(&dialog_list_mutex);
317
+		lock(dialog_list_mutex);
318 318
 		rms_dialog_info_t *di;
319 319
 		clist_foreach(rms_dialog_list, di, next)
320 320
 		{
321 321
 			di = rms_dialog_action_check(di);
322 322
 			//LM_INFO("next ... si[%p]\n", di);
323 323
 		}
324
-		unlock(&dialog_list_mutex);
324
+		unlock(dialog_list_mutex);
325 325
 		usleep(10000);
326 326
 	}
327 327
 }
... ...
@@ -755,9 +755,9 @@ static void rms_action_add(rms_dialog_info_t *di, rms_action_t *a)
755 755
 
756 756
 static void rms_action_add_sync(rms_dialog_info_t *di, rms_action_t *a)
757 757
 {
758
-	lock(&dialog_list_mutex);
758
+	lock(dialog_list_mutex);
759 759
 	rms_action_add(di, a);
760
-	unlock(&dialog_list_mutex);
760
+	unlock(dialog_list_mutex);
761 761
 }
762 762
 
763 763
 // Called when receiving BYE
... ...
@@ -39,7 +39,7 @@
39 39
 #include "rms_media.h"
40 40
 #include "rms_dialog_info.h"
41 41
 
42
-extern gen_lock_t dialog_list_mutex;
42
+extern gen_lock_t *dialog_list_mutex;
43 43
 
44 44
 
45 45