Blame view
fs/xfs/mrlock.h
2.18 KB
1da177e4c
|
1 |
/* |
72c93bcc6
|
2 |
* Copyright (c) 2000-2006 Silicon Graphics, Inc. |
7b7187698
|
3 |
* All Rights Reserved. |
1da177e4c
|
4 |
* |
7b7187698
|
5 6 |
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as |
1da177e4c
|
7 8 |
* published by the Free Software Foundation. * |
7b7187698
|
9 10 11 12 |
* This program is distributed in the hope that it would be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. |
1da177e4c
|
13 |
* |
7b7187698
|
14 15 16 |
* You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1da177e4c
|
17 18 19 20 21 |
*/ #ifndef __XFS_SUPPORT_MRLOCK_H__ #define __XFS_SUPPORT_MRLOCK_H__ #include <linux/rwsem.h> |
1da177e4c
|
22 23 |
typedef struct { struct rw_semaphore mr_lock; |
742ae1e35
|
24 |
#if defined(DEBUG) || defined(XFS_WARN) |
1da177e4c
|
25 |
int mr_writer; |
579aa9caf
|
26 |
#endif |
1da177e4c
|
27 |
} mrlock_t; |
742ae1e35
|
28 |
#if defined(DEBUG) || defined(XFS_WARN) |
1da177e4c
|
29 |
#define mrinit(mrp, name) \ |
72c93bcc6
|
30 |
do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0) |
579aa9caf
|
31 32 33 34 |
#else #define mrinit(mrp, name) \ do { init_rwsem(&(mrp)->mr_lock); } while (0) #endif |
1da177e4c
|
35 36 |
#define mrlock_init(mrp, t,n,s) mrinit(mrp, n) #define mrfree(mrp) do { } while (0) |
1da177e4c
|
37 |
|
f7c66ce3f
|
38 39 40 41 42 43 44 45 |
static inline void mraccess_nested(mrlock_t *mrp, int subclass) { down_read_nested(&mrp->mr_lock, subclass); } static inline void mrupdate_nested(mrlock_t *mrp, int subclass) { down_write_nested(&mrp->mr_lock, subclass); |
742ae1e35
|
46 |
#if defined(DEBUG) || defined(XFS_WARN) |
f7c66ce3f
|
47 |
mrp->mr_writer = 1; |
579aa9caf
|
48 |
#endif |
f7c66ce3f
|
49 |
} |
1da177e4c
|
50 51 52 53 54 55 56 57 58 |
static inline int mrtryaccess(mrlock_t *mrp) { return down_read_trylock(&mrp->mr_lock); } static inline int mrtryupdate(mrlock_t *mrp) { if (!down_write_trylock(&mrp->mr_lock)) return 0; |
742ae1e35
|
59 |
#if defined(DEBUG) || defined(XFS_WARN) |
1da177e4c
|
60 |
mrp->mr_writer = 1; |
579aa9caf
|
61 |
#endif |
1da177e4c
|
62 63 |
return 1; } |
579aa9caf
|
64 |
static inline void mrunlock_excl(mrlock_t *mrp) |
1da177e4c
|
65 |
{ |
742ae1e35
|
66 |
#if defined(DEBUG) || defined(XFS_WARN) |
579aa9caf
|
67 68 69 |
mrp->mr_writer = 0; #endif up_write(&mrp->mr_lock); |
1da177e4c
|
70 |
} |
579aa9caf
|
71 |
static inline void mrunlock_shared(mrlock_t *mrp) |
1da177e4c
|
72 |
{ |
579aa9caf
|
73 |
up_read(&mrp->mr_lock); |
1da177e4c
|
74 |
} |
579aa9caf
|
75 |
static inline void mrdemote(mrlock_t *mrp) |
1da177e4c
|
76 |
{ |
742ae1e35
|
77 |
#if defined(DEBUG) || defined(XFS_WARN) |
579aa9caf
|
78 |
mrp->mr_writer = 0; |
1da177e4c
|
79 |
#endif |
579aa9caf
|
80 81 |
downgrade_write(&mrp->mr_lock); } |
1da177e4c
|
82 83 |
#endif /* __XFS_SUPPORT_MRLOCK_H__ */ |