Browse code

kex: use mutex to sync the mod mem stats rpc commands

- related to GH #2433

Daniel-Constantin Mierla authored on 09/09/2020 15:57:10
Showing 1 changed files
... ...
@@ -35,7 +35,9 @@
35 35
 #include "../../core/pt.h"
36 36
 #include "../../core/sr_module.h"
37 37
 #include "../../core/events.h"
38
-#include "../../core/mem/f_malloc.h"
38
+#include "../../core/mem/pkg.h"
39
+#include "../../core/mem/shm.h"
40
+#include "../../core/locking.h"
39 41
 #include "../../core/rpc.h"
40 42
 #include "../../core/rpc_lookup.h"
41 43
 
... ...
@@ -47,6 +49,9 @@
47 49
 #define DBG_MOD_ALL_FLAG		3 /* 1|2  - print pkg+shm (1+2) memory stats */
48 50
 #define DBG_MOD_INF_FLAG		4 /* 1<<2 - print more info in the stats */
49 51
 
52
+
53
+static gen_lock_t *kex_rpc_mod_mem_stats_lock = NULL;
54
+
50 55
 /**
51 56
  *
52 57
  */
... ...
@@ -248,7 +253,9 @@ static void rpc_mod_mem_stats_mode(rpc_t *rpc, void *ctx, int fmode)
248 253
  */
249 254
 static void rpc_mod_mem_stats(rpc_t *rpc, void *ctx)
250 255
 {
251
-	 rpc_mod_mem_stats_mode(rpc, ctx, 0);
256
+	lock_get(kex_rpc_mod_mem_stats_lock);
257
+	rpc_mod_mem_stats_mode(rpc, ctx, 0);
258
+	lock_release(kex_rpc_mod_mem_stats_lock);
252 259
 }
253 260
 
254 261
 /**
... ...
@@ -256,7 +263,9 @@ static void rpc_mod_mem_stats(rpc_t *rpc, void *ctx)
256 263
  */
257 264
 static void rpc_mod_mem_statsx(rpc_t *rpc, void *ctx)
258 265
 {
259
-	 rpc_mod_mem_stats_mode(rpc, ctx, DBG_MOD_INF_FLAG);
266
+	lock_get(kex_rpc_mod_mem_stats_lock);
267
+	rpc_mod_mem_stats_mode(rpc, ctx, DBG_MOD_INF_FLAG);
268
+	lock_release(kex_rpc_mod_mem_stats_lock);
260 269
 }
261 270
 
262 271
 
... ...
@@ -275,6 +284,15 @@ rpc_export_t kex_mod_rpc[] = {
275 284
  */
276 285
 int mod_stats_init_rpc(void)
277 286
 {
287
+	kex_rpc_mod_mem_stats_lock = lock_alloc();
288
+	if(kex_rpc_mod_mem_stats_lock == NULL) {
289
+		LM_ERR("failed to allocate the lock\n");
290
+		return -1;
291
+	}
292
+	if(lock_init(kex_rpc_mod_mem_stats_lock) == NULL) {
293
+		LM_ERR("failed to init the lock\n");
294
+		return -1;
295
+	}
278 296
 	if (rpc_register_array(kex_mod_rpc)!=0)
279 297
 	{
280 298
 		LM_ERR("failed to register RPC commands\n");