1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
6 #ifndef __XFS_SUPPORT_MRLOCK_H__
7 #define __XFS_SUPPORT_MRLOCK_H__
9 #include <linux/rwsem.h>
12 struct rw_semaphore mr_lock;
13 #if defined(DEBUG) || defined(XFS_WARN)
18 #if defined(DEBUG) || defined(XFS_WARN)
19 #define mrinit(mrp, name) \
20 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
22 #define mrinit(mrp, name) \
23 do { init_rwsem(&(mrp)->mr_lock); } while (0)
26 #define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
27 #define mrfree(mrp) do { } while (0)
29 static inline void mraccess_nested(mrlock_t *mrp, int subclass)
31 down_read_nested(&mrp->mr_lock, subclass);
34 static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
36 down_write_nested(&mrp->mr_lock, subclass);
37 #if defined(DEBUG) || defined(XFS_WARN)
42 static inline int mrtryaccess(mrlock_t *mrp)
44 return down_read_trylock(&mrp->mr_lock);
47 static inline int mrtryupdate(mrlock_t *mrp)
49 if (!down_write_trylock(&mrp->mr_lock))
51 #if defined(DEBUG) || defined(XFS_WARN)
57 static inline void mrunlock_excl(mrlock_t *mrp)
59 #if defined(DEBUG) || defined(XFS_WARN)
62 up_write(&mrp->mr_lock);
65 static inline void mrunlock_shared(mrlock_t *mrp)
67 up_read(&mrp->mr_lock);
70 static inline void mrdemote(mrlock_t *mrp)
72 #if defined(DEBUG) || defined(XFS_WARN)
75 downgrade_write(&mrp->mr_lock);
78 #endif /* __XFS_SUPPORT_MRLOCK_H__ */