summaryrefslogtreecommitdiff
path: root/libpthread/nptl/DESIGN-rwlock.txt
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2005-05-20 19:02:51 +0000
committerEric Andersen <andersen@codepoet.org>2005-05-20 19:02:51 +0000
commit124af9f4b2b77b1510d88cfc8092c788d7e513c7 (patch)
treeccce720bef4c1c604417e2082cf9997a8d6dd7ab /libpthread/nptl/DESIGN-rwlock.txt
parent8028f35dbe29c5ace3883005e08ac91d873553b2 (diff)
Back out nptl changes, which for now will be done in branches/uClibc-nptl
Diffstat (limited to 'libpthread/nptl/DESIGN-rwlock.txt')
-rw-r--r--libpthread/nptl/DESIGN-rwlock.txt113
1 files changed, 0 insertions, 113 deletions
diff --git a/libpthread/nptl/DESIGN-rwlock.txt b/libpthread/nptl/DESIGN-rwlock.txt
deleted file mode 100644
index 810d1b8f3..000000000
--- a/libpthread/nptl/DESIGN-rwlock.txt
+++ /dev/null
@@ -1,113 +0,0 @@
-Reader Writer Locks pseudocode
-==============================
-
- pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
- pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
- pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
-
-struct pthread_rwlock_t {
-
- unsigned int lock:
- - internal mutex
-
- unsigned int writers_preferred;
- - locking mode: 0 recursive, readers preferred
- 1 nonrecursive, writers preferred
-
- unsigned int readers;
- - number of read-only references various threads have
-
- pthread_t writer;
- - descriptor of the writer or 0
-
- unsigned int readers_wakeup;
- - 'all readers should wake up' futex.
-
- unsigned int writer_wakeup;
- - 'one writer should wake up' futex.
-
- unsigned int nr_readers_queued;
- - number of readers queued up.
-
- unsigned int nr_writers_queued;
- - number of writers queued up.
-}
-
-pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
- for (;;) {
- if (!rwlock->writer && (!rwlock->nr_writers_queued ||
- !rwlock->writers_preferred))
- break;
-
- rwlock->nr_readers_queued++;
- val = rwlock->readers_wakeup;
- lll_unlock(rwlock->lock);
-
- futex_wait(&rwlock->readers_wakeup, val)
-
- lll_lock(rwlock->lock);
- rwlock->nr_readers_queued--;
- }
- rwlock->readers++;
- lll_unlock(rwlock->lock);
-}
-
-pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
-{
- int result = EBUSY;
- lll_lock(rwlock->lock);
- if (!rwlock->writer && (!rwlock->nr_writers_queued ||
- !rwlock->writers_preferred))
- rwlock->readers++;
- lll_unlock(rwlock->lock);
- return result;
-}
-
-pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
- for (;;) {
- if (!rwlock->writer && !rwlock->readers)
- break;
-
- rwlock->nr_writers_queued++;
- val = rwlock->writer_wakeup;
- lll_unlock(rwlock->lock);
-
- futex_wait(&rwlock->writer_wakeup, val);
-
- lll_lock(rwlock->lock);
- rwlock->nr_writers_queued--;
- }
- rwlock->writer = pthread_self();
- lll_unlock(rwlock->lock);
-}
-
-pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
-
- if (rwlock->writer)
- rwlock->writer = 0;
- else
- rwlock->readers--;
-
- if (!rwlock->readers) {
- if (rwlock->nr_writers_queued) {
- ++rwlock->writer_wakeup;
- lll_unlock(rwlock->lock);
- futex_wake(&rwlock->writer_wakeup, 1);
- return;
- } else
- if (rwlock->nr_readers_queued) {
- ++rwlock->readers_wakeup;
- lll_unlock(rwlock->lock);
- futex_wake(&rwlock->readers_wakeup, MAX_INT);
- return;
- }
- }
-
- lll_unlock(rwlock->lock);
-}