[OpenSER-Devel] add lock in AVP

Di-Shi Sun di-shi at transnexus.com
Wed Oct 31 14:18:23 UTC 2007


Hi Henning,

Our test has not reached a patch level yet. Let me explain the idea.

Our original logic:
1. We have a data structure, say dest_struct. We save it as an AVP value.
2. 180 and 200 trigger a tm callback function. This function sets a flag in
the AVP value to mark it as used and do something, say increasing a count by
one. If this flag has been set, the callback function do nothing. As we
know, there may be a race condition for accessing the flag and the count is
increased twice.

Our test:
1. Add a lock in the data structure, say dest_struct->lock. The lock is
initialized. The data structure is saved as an AVP value.
2. 180 and 200 trigger the tm callback function. After the AVP value,
dest_struct, is obtained, request dest_struct->lock, then set the flag,
release the lock.

It works for FAST_LOCK.
1. lock_init only set the lock to 0. Saving the data structure as an AVP
value (copy the data structure from private memory to shared memory) does
not change it. It does not dunplicate it too. But it may be not ture for
other lock mechanism. There is a small trick may be useful. We can save the
data structure as an AVP value, obtain the AVP value, then initialize the
lock.
2. FAST_LOCK lock_destroy do nothing. This is the most important part. For
other lock mechanism, the lock must be destroyed. But our module does not
know when the AVP is discarded. We cannot destroy the lock. It causes
resource leak.

The idea:
1. Add a lock in AVP structure.
2. Provide a set of AVP functions to access the lock. I mean using the lock
but hide it.
3. Init the lock when an AVP is created.
4. Destroy the lock when the AVP is destroyed.

What do you think?

Regards,

Di-Shi Sun.

----- Original Message ----- 
From: "Henning Westerholt" <henning.westerholt at 1und1.de>
To: <devel at lists.openser.org>
Cc: "Di-Shi Sun" <di-shi at transnexus.com>; "Support TransNexus"
<support at transnexus.com>
Sent: Wednesday, October 31, 2007 6:09 PM
Subject: Re: [OpenSER-Devel] add lock in AVP


> On Tuesday 30 October 2007, Di-Shi Sun wrote:
> > Hi Developers,
> >
> > Is anyone interested in adding a lock in AVP? We found it is necessary
to
> > do it in core or avp module instead of in our module. The reason is we
> > cannot destroy the locks in our module. In fact, FAST_LOCK does nothing
to
> > destroy a lock. But other lock mechanisms may want to destroy the locks.
> >
> > We had tested adding FAST_LOCK type locks in our AVPs. It worked fine
(no
> > crash, no dead lock, no race condition again) for our test cases.
>
> Hi Di-Shi,
>
> where do you exactly add the lock? In the tm module, or in the AVP list
> implementation? Could you please post a patch of the changes you did, so i
> can take a look?
>
> We've tried to implemented a bugfix too, but it don't seems work for all
our
> test cases yet. It would be really nice to have a fix for this problem in
the
> trunk.
>
> Thank you,
>
> Henning
>
>





More information about the Devel mailing list