[sr-dev] shared memory between multiple forks in custom module

Cockhootec Yahrabee cockootec at gmail.com
Sat Apr 9 16:16:21 CEST 2016


Hi guys!

I am developing custom kamailio module in which I am parsing some
properties from incoming SIP messages and I am persisting them within
linked list of my custom structure.

I am also accessing this linked list and I am deciding on the data which
part of my program will be executed. I am also at some point removing items
from linked list.


I was testing my module only in single fork while I was developing it but
now I want to use it with multiple forks. My linked list is allocated via
`shm_malloc` function and all data within it as well. I assumed that I need
to allocate some lock as well so at the time of creation single node I am
allocating lock by
http://www.asipto.com/pub/kamailio-devel-guide/#c03lock_init

Unfortunately I didn't find anywhere how should I access this kind of data.
Do I need to check every time I want to access my structure if the lock is
unlocked and if I am accessing it I need to lock it? Or are these actions
performed by kamailio internally?

Another question is if it is sufficient to have one lock per structure or I
need to lock every structure within that structure? For instance:

typedef struct node {
    char *some_property;

    another_node_t *some_other_property;
    another_node_t *another_property;

    struct node *prev;
    struct node *next;

    gen_lock_t *lock;

} node_t;


In this scenario do I need create `gen_lock_t` also within `another_node_t`
structure?


Thanks in advance for any help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20160409/3824d97a/attachment.html>


More information about the sr-dev mailing list