[asterisk-dev] Using pthread_rwlock_t in Asterisk

Russell Bryant russell at digium.com
Wed Mar 1 12:24:17 MST 2006


Hey guys,

During some recent reading about pthreads, I came across a section 
discussion pthread_rwlock_t.  The question immediately occurred to me as 
to why we don't use these anywhere in Asterisk.  It seems to me that 
they would be immediately beneficial in these two places:

1) include/asterisk/linkedlists.h

Traversing linked lists implemented using these macros is often a 
read-only operation.  The transition would be rather painless since all 
of the details are hidden in the definitions in the header file.  We 
would have to create an AST_LIST_RDLOCK and AST_LST_WRLOCK.  Then, we 
could define AST_LIST_LOCK to be AST_LIST_WRLOCK for the sake of an easy 
transition.

2) include/asterisk/astobj.h

Interestingly enough, this interface was written with the distinction 
between a read lock and write lock in mind.  The macros ASTOBJ_RDLOCK 
and ASTOBJ_WRLOCK are already defined.  However, the locking is 
implemented using a mutex, which of course means that they are the exact 
same thing.

The real work involved in making rwlocks usable in asterisk is adapting 
the interface we currently have in lock.h for thread debugging to allow 
the use of a rwlock in addition to a mutex.

Are there portability, performance, or any other kind of issues that I 
have not come across that would serve as a reason why this project would 
not be a good idea?

Any feedback would be appreciated.

Thanks!

Russell Bryant



More information about the asterisk-dev mailing list