[Asterisk-Dev] ASTOBJ update

Kevin P. Fleming kpfleming at starnetworks.us
Tue Dec 28 07:54:09 MST 2004


Matthew Boehm wrote:

> For those of us who aren't hard-core C programmers, could someone explain
> why/how the new macro-enabled code is better than before? An easy example is
> here:
> 
> #define ASTOBJ_WRLOCK(object) ast_mutex_lock(&(object)->_lock)
> 
> Why is using this macro better than just calling the function? What kind of
> performance gain is seen? Where is it seen?

The benefit is not performance in this case; it's the ability for us to 
change ASTOBJ_WRLOCK later to use a _different_ locking mechanism 
without having to modify all the callers. That's also the reason for 
RDLOCK and WRLOCK both existing, even though they call the same function 
right now. When I write the documentation for this stuff, I'll document 
when each should be used; if sometime down the road we switch to rwlocks 
instead of mutexes, then all callers benefit from that change automatically.



More information about the asterisk-dev mailing list