2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_SUPPORT_MRLOCK_H__
33 #define __XFS_SUPPORT_MRLOCK_H__
35 #include <linux/rwsem.h>
37 enum { MR_NONE
, MR_ACCESS
, MR_UPDATE
};
40 struct rw_semaphore mr_lock
;
44 #define mrinit(mrp, name) \
45 ( (mrp)->mr_writer = 0, init_rwsem(&(mrp)->mr_lock) )
46 #define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
47 #define mrfree(mrp) do { } while (0)
48 #define mraccess(mrp) mraccessf(mrp, 0)
49 #define mrupdate(mrp) mrupdatef(mrp, 0)
51 static inline void mraccessf(mrlock_t
*mrp
, int flags
)
53 down_read(&mrp
->mr_lock
);
56 static inline void mrupdatef(mrlock_t
*mrp
, int flags
)
58 down_write(&mrp
->mr_lock
);
62 static inline int mrtryaccess(mrlock_t
*mrp
)
64 return down_read_trylock(&mrp
->mr_lock
);
67 static inline int mrtryupdate(mrlock_t
*mrp
)
69 if (!down_write_trylock(&mrp
->mr_lock
))
75 static inline void mrunlock(mrlock_t
*mrp
)
79 up_write(&mrp
->mr_lock
);
81 up_read(&mrp
->mr_lock
);
85 static inline void mrdemote(mrlock_t
*mrp
)
88 downgrade_write(&mrp
->mr_lock
);
93 * Debug-only routine, without some platform-specific asm code, we can
94 * now only answer requests regarding whether we hold the lock for write
95 * (reader state is outside our visibility, we only track writer state).
96 * Note: means !ismrlocked would give false positivies, so don't do that.
98 static inline int ismrlocked(mrlock_t
*mrp
, int type
)
100 if (mrp
&& type
== MR_UPDATE
)
101 return mrp
->mr_writer
;
106 #endif /* __XFS_SUPPORT_MRLOCK_H__ */