[SR-Users] cfgutils lock / unlock + $sht() variables.
Daniel-Constantin Mierla
miconda at gmail.com
Mon Jul 2 21:20:35 CEST 2012
Hello,
On 6/29/12 11:07 PM, Vitaliy Aleksandrov wrote:
> Hi all,
>
> I use $sht() pseudo-variabled provided by htable module for caching
> various information about sip customers. I thought that htable has
> some locking mechanism inside it and today while i was reading
> core-cookbook i payed attention to one example with the lock/unlock
> functions and $sht():
>
> lock("calls-to::10.10.10.10");
> $sht(a=>calls-to::10.10.10.10) =
> $sht(a=>calls-to::10.10.10.10) + 1;
> unlock("calls-to::10.10.10.10");
>
> According to that example an explicit locking mechanism should be used
> when i want to write something to a hash table.
> On the other hand there are no locks in htable documentation.
>
> So the question is when do the explicit locks should be used and for
> what purpose ?
reading and writing in hash table is under the lock. But the increment
operation as it is presented above requires first to read and then to
write -- for that is recommended you use a lock to avoid races.
If it is just increment/decrement operation in htable, then you can use
$shtinc(...)/$shtdec(...) for it:
http://www.kamailio.org/wiki/cookbooks/3.3.x/pseudovariables#shtinc_htable_key
Cheers,
Daniel
--
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Training, Seattle, USA, Sep 23-26, 2012 - http://asipto.com/u/katu
Kamailio Practical Workshop, Netherlands, Sep 10-12, 2012 - http://asipto.com/u/kpw
More information about the sr-users
mailing list