[asterisk-dev] Dialplan - critical sections / semaphores /
run-all-of
Stephen Davies
stephen.l.davies at gmail.com
Wed Jun 7 14:34:18 MST 2006
Hi,
I'm trying to develop a tricky bit of dialplan logic which needs
coordination between multiple calls - and I've run into two things for
which the available apps and functions don't seem to have a solution:
I'm posting firstly in case I've missed what I need, and secondly for
ideas on how best to add these capabilities:
1) "Critical section" (semaphores)
I have code manipulating astdb entries that need to be protected by
mutexes. For instance, this simple line:
exten => s,n,Set(DB(FIFO/${ARG1})=${DB(FIFO/${ARG1})}${ARG2})
If two calls come through here at the same time then one of the
appends will be lost. This line needs a mutex to ensure only one call
runs this line at a time.
It can also be an issue for multiple lines. For instance:
exten => s,n,Set(next=${DB(some/key)})
exten => s,n,Set(DB(some/key)=${next:1})
exten => s,n,Set(next=${next:0:1})
I want to be sure that every call will get a different "next", and the
DB entry will be correctly updated. I need these three lines
protected by a mutex.
My idea was to put these sorts of code sections into a Macro and add a
new way to call a Macro that first locks an associated mutex. Or
maybe, at the start of a macro you can lock the mutex. On completion,
hangup or jump-out the mutex would be released again. I don't really
want to expose mutex primitives into the dialplan directly - so
"tagging" a Macro seems like a good way to keep the mutex stuff in the
c-code proper and provides quite clean and understandable semantics in
the language.
What do you think?
2) Guaranteed "run to completion"
I have fragments of code where I can't have a caller hangup stop
execution in the middle. I need to carry on until I get to a "safe"
point in order to leave the "state" consistent. A slightly contrived
example:
exten => s,1,Set(DB(credit/${account})=$[${DB(credit/${account})} -
${ANSWEREDTIME}]) ; sheesh - $[${oh(my)}goodness]
exten => s,2,Set(DB(used/${account})=$[${DB(used/${account})} +
${ANSWEREDTIME}])
This doesn't need a mutex lock, but both lines must run if the
"credit" and "used" are to stay consistent.
Not sure how best to handle in the dialplan. Perhaps again a way to
mark a Macro for this treatment?
There are ways to dodge around these missing features - calling AGI
for instance. But I think they'd add quite a bit of power to the
dialplan language.
Regards,
Steve
More information about the asterisk-dev
mailing list