--- thr_rwlock.c.orig 2011-02-23 22:12:32.000000000 +0000 +++ thr_rwlock.c 2011-02-24 07:42:31.000000000 +0000 @@ -126,6 +126,10 @@ prwlock = *rwlock; } + if (__predict_false(prwlock->owner == curthread)) { + return (EDEADLK); + } + if (curthread->rdlock_count) { /* * To avoid having to track all the rdlocks held by @@ -219,6 +223,10 @@ prwlock = *rwlock; } + if (__predict_false(prwlock->owner == curthread)) { + return (EDEADLK); + } + if (curthread->rdlock_count) { /* * To avoid having to track all the rdlocks held by @@ -263,6 +271,10 @@ prwlock = *rwlock; } + if (__predict_false(prwlock->owner == curthread)) { + return (EDEADLK); + } + ret = _thr_rwlock_trywrlock(&prwlock->lock); if (ret == 0) prwlock->owner = curthread; @@ -290,6 +302,10 @@ prwlock = *rwlock; } + if (__predict_false(prwlock->owner == curthread)) { + return (EDEADLK); + } + /* * POSIX said the validity of the abstimeout parameter need * not be checked if the lock can be immediately acquired.