File: /usr/include/linux/locks.h
1 #ifndef _LINUX_LOCKS_H
2 #define _LINUX_LOCKS_H
3
4 #ifndef _LINUX_MM_H
5 #include <linux/mm.h>
6 #endif
7 #ifndef _LINUX_PAGEMAP_H
8 #include <linux/pagemap.h>
9 #endif
10
11 /*
12 * Buffer cache locking - note that interrupts may only unlock, not
13 * lock buffers.
14 */
15 extern void __wait_on_buffer(struct buffer_head *);
16
17 extern inline void wait_on_buffer(struct buffer_head * bh)
18 {
19 if (test_bit(BH_Lock, &bh->b_state))
20 __wait_on_buffer(bh);
21 }
22
23 extern inline void lock_buffer(struct buffer_head * bh)
24 {
25 while (test_and_set_bit(BH_Lock, &bh->b_state))
26 __wait_on_buffer(bh);
27 }
28
29 extern inline void unlock_buffer(struct buffer_head *bh)
30 {
31 clear_bit(BH_Lock, &bh->b_state);
32 smp_mb__after_clear_bit();
33 if (waitqueue_active(&bh->b_wait))
34 wake_up(&bh->b_wait);
35 }
36
37 /*
38 * super-block locking. Again, interrupts may only unlock
39 * a super-block (although even this isn't done right now.
40 * nfs may need it).
41 */
42 extern void __wait_on_super(struct super_block *);
43
44 extern inline void wait_on_super(struct super_block * sb)
45 {
46 if (sb->s_lock)
47 __wait_on_super(sb);
48 }
49
50 extern inline void lock_super(struct super_block * sb)
51 {
52 #ifdef CONFIG_SMP
53 if (current->lock_depth < 0)
54 BUG();
55 #endif
56 if (sb->s_lock)
57 __wait_on_super(sb);
58 sb->s_lock = 1;
59 }
60
61 extern inline void unlock_super(struct super_block * sb)
62 {
63 sb->s_lock = 0;
64 /*
65 * No need of any barrier, we're protected by
66 * the big kernel lock here... unfortunately :)
67 */
68 if (waitqueue_active(&sb->s_wait))
69 wake_up(&sb->s_wait);
70 }
71
72 #endif /* _LINUX_LOCKS_H */
73
74