[Kamailio-Devel] Conditional lock_get()

Iñaki Baz Castillo ibc at aliax.net
Fri Jan 9 19:31:48 CET 2009


El Viernes, 9 de Enero de 2009, Henning Westerholt escribió:
> On Friday 09 January 2009, Iñaki Baz Castillo wrote:
> > [..]
> > Anyway, if I get the desired behaviour it could occur that a process is
> > reading the PCRE (so without "lock_get()") and at the same time the MI
> > function modifies it, which could cause a segmentation fault.
> >
> > Any suggestion? Perhaps I should use "lock_get()" in each read access?
> > It's the simplest solution, but what about performance?
>
> Hi Iñaki,
>
> using the lock for every read access will work, and normally you should not
> notice any performance problem. This is used in many modules, for example
> in the userblacklist.c, check_blacklist() function.
>
> If you don't want this its gets a little bit more complicated. For example
> in the cr module we use a get_data() function, which provides access to the
> data and is protected from a lock. This function increment a reference
> counter, which is checked from the reload_route_data() function that is
> called from the FIFO cmd. After each read access the counter is decremented
> again, which is again protected by the lock. The FIFO cmd allocates some
> new memory when new data is reloaded, and swaps this with the old pointer
> when possible. It also waits a bit if the data is accessed at the moment.
> Take a look at the trunk, cr_data.c file for the code.
>
> Perhaps this help you to get an idea. :-) Cheers,

Really thanks a lot for the explanation.



-- 
Iñaki Baz Castillo



More information about the Devel mailing list