BNX2X: spatch signed typedefs
[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 #ifndef ROS_KERN_RWLOCK_H
14 #define ROS_KERN_RWLOCK_H
15
16 #include <ros/common.h>
17 #include <kthread.h>
18 #include <atomic.h>
19
20 struct rwlock {
21         spinlock_t                                      lock;
22         atomic_t                                        nr_readers;
23         bool                                            writing;
24         struct cond_var                         readers;
25         struct cond_var                         writers;
26 };
27 typedef struct rwlock rwlock_t;
28
29 void rwinit(struct rwlock *rw_lock);
30 void rlock(struct rwlock *rw_lock);
31 bool canrlock(struct rwlock *rw_lock);
32 void runlock(struct rwlock *rw_lock);
33 void wlock(struct rwlock *rw_lock);
34 void wunlock(struct rwlock *rw_lock);
35
36 #endif /* ROS_KERN_RWLOCK_H */