Module: kamailio
Branch: master
Commit: 13bdd0e15883a07d396210b8a372c1b51786f2a9
URL: 
https://github.com/kamailio/kamailio/commit/13bdd0e15883a07d396210b8a372c1b51786f2a9

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2017-08-11T15:21:59+02:00

core: mem/shm - shared memory api updated to allow locking by manager

- instead of generic global lock, allow memory manager to handle locking
  for shared memory

---

Modified: src/core/mem/memapi.h
Modified: src/core/mem/shm.c
Modified: src/core/mem/shm.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/13bdd0e15883a07d396210b8a372c1b51786f2a9.diff
Patch: 
https://github.com/kamailio/kamailio/commit/13bdd0e15883a07d396210b8a372c1b51786f2a9.patch

---

diff --git a/src/core/mem/memapi.h b/src/core/mem/memapi.h
index 198bd4d25a..dc1cd80f03 100644
--- a/src/core/mem/memapi.h
+++ b/src/core/mem/memapi.h
@@ -46,6 +46,9 @@ typedef void* (*sr_resize_f)(void* mbp, void* p, size_t size);
 
 #endif /*DBG_SR_MEMORY*/
 
+typedef void  (*sr_shm_glock_f)(void* mbp);
+typedef void  (*sr_shm_gunlock_f)(void* mbp);
+
 typedef void  (*sr_mem_status_f)(void* mbp);
 typedef void  (*sr_mem_info_f)(void* mbp, struct mem_info* info);
 typedef unsigned long (*sr_mem_available_f)(void* mbp);
@@ -128,6 +131,10 @@ typedef struct sr_shm_api {
        sr_mem_mod_get_stats_f  xmodstats;
        /*memory stats free per module*/
        sr_mem_mod_free_stats_f xfmodstats;
+       /*memory managing global lock*/
+       sr_shm_glock_f          xglock;
+       /*memory managing global unlock*/
+       sr_shm_gunlock_f        xgunlock;
 } sr_shm_api_t;
 
 #endif
diff --git a/src/core/mem/shm.c b/src/core/mem/shm.c
index f48cf3baad..3dbc34f11a 100644
--- a/src/core/mem/shm.c
+++ b/src/core/mem/shm.c
@@ -48,8 +48,6 @@ void shm_core_destroy(void);
 static int _shm_core_shmid[SHM_CORE_POOLS_SIZE] = { -1 }; /*shared memory id*/
 #endif
 
-gen_lock_t* _shm_lock=0;
-
 static void* _shm_core_pools_mem[SHM_CORE_POOLS_SIZE] = { (void*)-1 };
 static int   _shm_core_pools_num = 1;
 
@@ -168,41 +166,6 @@ void* shm_core_get_pool(void)
 }
 
 /**
- * init the core lock
- */
-int shm_core_lock_init(void)
-{
-       if (_shm_lock) {
-               LM_DBG("shared memory lock initialized\n");
-               return 0;
-       }
-       _shm_lock=shm_malloc_unsafe(sizeof(gen_lock_t)); /* skip lock_alloc,
-                                                                               
                           race cond*/
-       if (_shm_lock==0){
-               LOG(L_CRIT, "could not allocate lock\n");
-               shm_core_destroy();
-               return -1;
-       }
-       if (lock_init(_shm_lock)==0){
-               LOG(L_CRIT, "could not initialize lock\n");
-               shm_core_destroy();
-               return -1;
-       }
-       return 0;
-}
-
-/**
- *
- */
-void shm_core_lock_destroy(void)
-{
-       if (_shm_lock){
-               DBG("destroying the shared memory lock\n");
-               lock_destroy(_shm_lock); /* we don't need to dealloc it*/
-       }
-}
-
-/**
  *
  */
 void shm_core_destroy(void)
@@ -255,6 +218,8 @@ int shm_init_api(sr_shm_api_t *ap)
        _shm_root.xdestroy       = ap->xdestroy;
        _shm_root.xmodstats      = ap->xmodstats;
        _shm_root.xfmodstats     = ap->xfmodstats;
+       _shm_root.xglock         = ap->xglock;
+       _shm_root.xgunlock       = ap->xgunlock;
        return 0;
 
 }
@@ -291,11 +256,10 @@ int shm_init_manager(char *name)
  */
 void shm_destroy_manager(void)
 {
-       shm_core_lock_destroy();
        if(_shm_root.xdestroy) {
-               _shm_root.xdestroy();
                LM_DBG("destroying memory manager: %s\n",
                                (_shm_root.mname)?_shm_root.mname:"unknown");
+               _shm_root.xdestroy();
        }
        shm_core_destroy();
 }
diff --git a/src/core/mem/shm.h b/src/core/mem/shm.h
index 7af16be766..5d58071359 100644
--- a/src/core/mem/shm.h
+++ b/src/core/mem/shm.h
@@ -38,12 +38,6 @@
 #include "../dprint.h"
 #include "../lock_ops.h" /* we don't include locking.h on purpose */
 
-extern gen_lock_t* _shm_lock;
-#define shm_lock()    lock_get(_shm_lock)
-#define shm_unlock()  lock_release(_shm_lock)
-int shm_core_lock_init(void);
-void shm_core_lock_destroy(void);
-
 extern sr_shm_api_t _shm_root;
 
 #ifdef DBG_SR_MEMORY
@@ -82,6 +76,9 @@ extern sr_shm_api_t _shm_root;
 #      define shm_mod_get_stats(x)     
_shm_root.xmodstats(_shm_root.mem_block, x)
 #      define shm_mod_free_stats(x)    _shm_root.xfmodstats(x)
 
+#      define shm_global_lock() _shm_root.xglock(_shm_root.mem_block)
+#      define shm_global_unlock() _shm_root.xgunlock(_shm_root.mem_block)
+
 
 void* shm_core_get_pool(void);
 int shm_init_api(sr_shm_api_t *ap);


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to