diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-15 13:50:45 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-15 21:33:45 +0100 |
| commit | d2f11d48b29de49265f1a0d997548074f80fe431 (patch) | |
| tree | eef11475b33f20c5530338af71f2a0ac991f312a /src/threads/synch.h | |
| parent | 32ae3483d635aa50a541ea215c7cb8c88ec4f9d8 (diff) | |
| download | pintos-d2f11d48b29de49265f1a0d997548074f80fe431.tar.gz | |
add rwlock implementation
Diffstat (limited to 'src/threads/synch.h')
| -rw-r--r-- | src/threads/synch.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/threads/synch.h b/src/threads/synch.h index a19e88b..a76eecc 100644 --- a/src/threads/synch.h +++ b/src/threads/synch.h @@ -41,6 +41,23 @@ void cond_wait (struct condition *, struct lock *); void cond_signal (struct condition *, struct lock *); void cond_broadcast (struct condition *, struct lock *); +/* Readers-writers lock. + + Implementation of "First readers-writers problem" from + https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem. */ +struct rwlock + { + struct semaphore resource; + struct lock rmutex; + unsigned readcount; + }; + +void rwlock_init (struct rwlock *); +void rwlock_write_p (struct rwlock *); +void rwlock_write_v (struct rwlock *); +void rwlock_read_p (struct rwlock *); +void rwlock_read_v (struct rwlock *); + /* Optimization barrier. The compiler will not reorder operations across an |
