[sr-dev] git:master:761eb061: kex: use mutex to sync the mod mem stats rpc commands
Daniel-Constantin Mierla
miconda at gmail.com
Wed Sep 9 18:00:12 CEST 2020
Module: kamailio
Branch: master
Commit: 761eb0616fea2a859a2c0abb652b22feb6f59859
URL: https://github.com/kamailio/kamailio/commit/761eb0616fea2a859a2c0abb652b22feb6f59859
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-09-09T17:57:10+02:00
kex: use mutex to sync the mod mem stats rpc commands
- related to GH #2433
---
Modified: src/modules/kex/mod_stats.c
---
Diff: https://github.com/kamailio/kamailio/commit/761eb0616fea2a859a2c0abb652b22feb6f59859.diff
Patch: https://github.com/kamailio/kamailio/commit/761eb0616fea2a859a2c0abb652b22feb6f59859.patch
---
diff --git a/src/modules/kex/mod_stats.c b/src/modules/kex/mod_stats.c
index a19a3ed3c3..25e3285c78 100644
--- a/src/modules/kex/mod_stats.c
+++ b/src/modules/kex/mod_stats.c
@@ -35,7 +35,9 @@
#include "../../core/pt.h"
#include "../../core/sr_module.h"
#include "../../core/events.h"
-#include "../../core/mem/f_malloc.h"
+#include "../../core/mem/pkg.h"
+#include "../../core/mem/shm.h"
+#include "../../core/locking.h"
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
@@ -47,6 +49,9 @@
#define DBG_MOD_ALL_FLAG 3 /* 1|2 - print pkg+shm (1+2) memory stats */
#define DBG_MOD_INF_FLAG 4 /* 1<<2 - print more info in the stats */
+
+static gen_lock_t *kex_rpc_mod_mem_stats_lock = NULL;
+
/**
*
*/
@@ -248,7 +253,9 @@ static void rpc_mod_mem_stats_mode(rpc_t *rpc, void *ctx, int fmode)
*/
static void rpc_mod_mem_stats(rpc_t *rpc, void *ctx)
{
- rpc_mod_mem_stats_mode(rpc, ctx, 0);
+ lock_get(kex_rpc_mod_mem_stats_lock);
+ rpc_mod_mem_stats_mode(rpc, ctx, 0);
+ lock_release(kex_rpc_mod_mem_stats_lock);
}
/**
@@ -256,7 +263,9 @@ static void rpc_mod_mem_stats(rpc_t *rpc, void *ctx)
*/
static void rpc_mod_mem_statsx(rpc_t *rpc, void *ctx)
{
- rpc_mod_mem_stats_mode(rpc, ctx, DBG_MOD_INF_FLAG);
+ lock_get(kex_rpc_mod_mem_stats_lock);
+ rpc_mod_mem_stats_mode(rpc, ctx, DBG_MOD_INF_FLAG);
+ lock_release(kex_rpc_mod_mem_stats_lock);
}
@@ -275,6 +284,15 @@ rpc_export_t kex_mod_rpc[] = {
*/
int mod_stats_init_rpc(void)
{
+ kex_rpc_mod_mem_stats_lock = lock_alloc();
+ if(kex_rpc_mod_mem_stats_lock == NULL) {
+ LM_ERR("failed to allocate the lock\n");
+ return -1;
+ }
+ if(lock_init(kex_rpc_mod_mem_stats_lock) == NULL) {
+ LM_ERR("failed to init the lock\n");
+ return -1;
+ }
if (rpc_register_array(kex_mod_rpc)!=0)
{
LM_ERR("failed to register RPC commands\n");
More information about the sr-dev
mailing list