[sr-dev] Fwd: Sharing static variables in external library across child proceses

Henning Westerholt hw at kamailio.org
Wed Jun 6 08:21:46 CEST 2018


Am Dienstag, 5. Juni 2018, 10:07:33 CEST schrieb User 721:
> I am adding a kamailio module that references an external C library that
> maintains a hashtable in global scope. I am wondering what practice I
> should follow so that:
> - This hashtable (which I don't control directly) is shared by all child
> processes
> - The hashtable is changed by one child process at a time

Hello,

if you can hold the data inside Kamailio you probably want to allocate the hash table in 
kamailio shared memory. Then you need to add proper locking to ensure that only one 
(child) process is changing it at a time, and also to protect against reads during eventual 
updates. The data is usually initialized during startup at mod_init.

Have a look to e.g. the userblacklist module how to use such a shared data structure, but 
there are many other modules as well. You find also some examples about shared memory 
and lock handling in the Kamailio developing guide.

If you can't hold the data inside Kamailio you want probably still to protect the access and 
modification with a lock. 

Maybe you can also think in just adding some sort of interface at the external hash table 
that you query e.g. with http or some other protocol.

Best regards,

Henning
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20180606/4cb19eb6/attachment.html>


More information about the sr-dev mailing list