diff options
author | mtm <mtm@FreeBSD.org> | 2004-01-19 14:51:45 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2004-01-19 14:51:45 +0000 |
commit | 2d3f49ebd38d6441b693d51adcf071088817ddf5 (patch) | |
tree | 8ea09bd49e1effae3ff537f35c5766a1cdc3bf69 /lib/libthr/thread/thr_private.h | |
parent | fc6eb88ff293065b8973e0a33349d6ee1547181c (diff) | |
download | FreeBSD-src-2d3f49ebd38d6441b693d51adcf071088817ddf5.zip FreeBSD-src-2d3f49ebd38d6441b693d51adcf071088817ddf5.tar.gz |
Implement reference counting of read-write locks. This uses
a list in the thread structure to keep track of the locks and
how many times they have been locked. This list is checked
on every lock and unlock. The traversal through the list is
O(n). Most applications don't hold so many locks at once that
this will become a problem. However, if it does become a problem
it might be a good idea to review this once libthr is
off probation and in the optimization cycle.
This fixes:
o deadlock when a thread tries to recursively acquire a
read lock when a writer is waiting on the lock.
o a thread could previously successfully unlock a lock it did not own
o deadlock when a thread tries to acquire a write lock on
a lock it already owns for reading or writing [ this is admittedly
not required by POSIX, but is nice to have ]
Diffstat (limited to 'lib/libthr/thread/thr_private.h')
-rw-r--r-- | lib/libthr/thread/thr_private.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 7a7412b..c2bea3f 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -423,6 +423,15 @@ struct pthread_specific_elem { int seqno; }; +struct rwlock_held { + LIST_ENTRY(rwlock_held) rh_link; + struct pthread_rwlock *rh_rwlock; + int rh_rdcount; + int rh_wrcount; +}; + +LIST_HEAD(rwlock_listhead, rwlock_held); + /* * Thread structure. */ @@ -562,6 +571,13 @@ struct pthread { */ TAILQ_HEAD(, pthread_mutex) mutexq; + /* + * List of read-write locks owned for reading _OR_ writing. + * This is accessed only by the current thread, so there's + * no need for mutual exclusion. + */ + struct rwlock_listhead *rwlockList; + void *ret; struct pthread_specific_elem *specific; int specific_data_count; |