[asterisk-dev] ast_rdlock_contexts() does not perform a read lock

Tilghman Lesher tilghman at meg.abyt.es
Tue May 3 23:58:58 CDT 2011


On Tuesday 03 May 2011 17:50:56 Byron Clark wrote:
> While hunting a deadlock (issue #19191) I saw that ast_rdlock_contexts()
> and ast_wrlock_contexts() both just call ast_mutex_lock(&conlock). From
> the naming of the functions, I would expect them to actually use a
> rwlock, in which case the deadlock I'm seeing wouldn't happen.
> 
> Is there some historical (or other) reason ast_rdlock_contexts() and
> ast_wrlock_contexts() just use a pthread_mutex_t instead of a
> pthread_rwlock_t? For reference, ast_rdlock_context() and
> ast_wrlock_context() do use a rwlock.

Yes, there's a historical reason, in that it once was a rwlock.  However,
because rwlocks are not recursive locks, and there was a code path that
required recursive locks to work, it was converted back to a mutex.  The
names were kept in place, merely to denote what the need is in the code.
Part of the reason why we use wrappers for such simple functions are when
we discover such problems and the code can be changed quickly.

I believe the specific code path related to device state and hints.

In any case, there is a specific locking order that should be followed
in the code, and not following that locking order is probably what caused
the deadlock.

-- 
Tilghman



More information about the asterisk-dev mailing list