net: Use chan flag O_NONBLOCK for nonblocking
[akaros.git] / kern / include / rwlock.h
1 /* Copyright (c) 2013 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Reader-writer queue locks (sleeping locks).
6  *
7  * Readers favor readers; writers favor writers.  Check out rwlock.c for more
8  * info. 
9  *
10  * One consequence of this: "if some reader holds a rwlock, then any other
11  * thread (including itself) can get an rlock". */
12
13 #pragma once
14
15 #include <ros/common.h>
16 #include <kthread.h>
17 #include <atomic.h>
18
19 struct rwlock {
20         spinlock_t                                      lock;
21         atomic_t                                        nr_readers;
22         bool                                            writing;
23         struct cond_var                         readers;
24         struct cond_var                         writers;
25 };
26 typedef struct rwlock rwlock_t;
27
28 void rwinit(struct rwlock *rw_lock);
29 void rlock(struct rwlock *rw_lock);
30 bool canrlock(struct rwlock *rw_lock);
31 void runlock(struct rwlock *rw_lock);
32 void wlock(struct rwlock *rw_lock);
33 void wunlock(struct rwlock *rw_lock);