2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef __XFS_SUPPORT_MRLOCK_H__
19 #define __XFS_SUPPORT_MRLOCK_H__
21 #include <linux/rwsem.h>
23 enum { MR_NONE, MR_ACCESS, MR_UPDATE };
26 struct rw_semaphore mr_lock;
30 #define mrinit(mrp, name) \
31 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
32 #define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
33 #define mrfree(mrp) do { } while (0)
35 static inline void mraccess(mrlock_t *mrp)
37 down_read(&mrp->mr_lock);
40 static inline void mrupdate(mrlock_t *mrp)
42 down_write(&mrp->mr_lock);
46 static inline void mraccess_nested(mrlock_t *mrp, int subclass)
48 down_read_nested(&mrp->mr_lock, subclass);
51 static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
53 down_write_nested(&mrp->mr_lock, subclass);
58 static inline int mrtryaccess(mrlock_t *mrp)
60 return down_read_trylock(&mrp->mr_lock);
63 static inline int mrtryupdate(mrlock_t *mrp)
65 if (!down_write_trylock(&mrp->mr_lock))
71 static inline void mrunlock(mrlock_t *mrp)
75 up_write(&mrp->mr_lock);
77 up_read(&mrp->mr_lock);
81 static inline void mrdemote(mrlock_t *mrp)
84 downgrade_write(&mrp->mr_lock);
89 * Debug-only routine, without some platform-specific asm code, we can
90 * now only answer requests regarding whether we hold the lock for write
91 * (reader state is outside our visibility, we only track writer state).
92 * Note: means !ismrlocked would give false positives, so don't do that.
94 static inline int ismrlocked(mrlock_t *mrp, int type)
96 if (mrp && type == MR_UPDATE)
97 return mrp->mr_writer;
102 #endif /* __XFS_SUPPORT_MRLOCK_H__ */