diff options
author | attilio <attilio@FreeBSD.org> | 2009-07-06 09:31:04 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2009-07-06 09:31:04 +0000 |
commit | daff94f8a671ee8db994d97c38dc8655a5c221ca (patch) | |
tree | fda37c75ad02ef9a28eba3bb3f0a4a66c184aa9d /lib/libthr | |
parent | 629faf0b20d18f48b008dea69c992c638ac335ca (diff) | |
download | FreeBSD-src-daff94f8a671ee8db994d97c38dc8655a5c221ca.zip FreeBSD-src-daff94f8a671ee8db994d97c38dc8655a5c221ca.tar.gz |
In the current code, rdlock_count is not correctly handled for some cases.
The most notable is that it is not bumped in rwlock_rdlock_common() when
the hard path (__thr_rwlock_rdlock()) returns successfully.
This can lead to deadlocks in libthr when rwlocks recursion in read mode
happens.
Fix the interested parts by correctly handling rdlock_count.
PR: threads/136345
Reported by: rink
Tested by: rink
Reviewed by: jeff
Approved by: re (kib)
MFC: 2 weeks
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/thread/thr_rtld.c | 2 | ||||
-rw-r--r-- | lib/libthr/thread/thr_rwlock.c | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/libthr/thread/thr_rtld.c b/lib/libthr/thread/thr_rtld.c index 7e26340..4db08bd 100644 --- a/lib/libthr/thread/thr_rtld.c +++ b/lib/libthr/thread/thr_rtld.c @@ -114,6 +114,7 @@ _thr_rtld_rlock_acquire(void *lock) THR_CRITICAL_ENTER(curthread); while (_thr_rwlock_rdlock(&l->lock, 0, NULL) != 0) ; + curthread->rdlock_count++; RESTORE_ERRNO(); } @@ -148,6 +149,7 @@ _thr_rtld_lock_release(void *lock) state = l->lock.rw_state; if (_thr_rwlock_unlock(&l->lock) == 0) { + curthread->rdlock_count--; if ((state & URWLOCK_WRITE_OWNER) == 0) { THR_CRITICAL_LEAVE(curthread); } else { diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index 641749b..de61e51 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -177,10 +177,11 @@ rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime) /* if interrupted, try to lock it in userland again. */ if (_thr_rwlock_tryrdlock(&prwlock->lock, flags) == 0) { ret = 0; - curthread->rdlock_count++; break; } } + if (ret == 0) + curthread->rdlock_count++; return (ret); } |