Merge tag 'extcon-next-for-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / fs / xfs / mrlock.h
blob79155eec341bff4b6718a0b50d6ec60475c329f9
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6 #ifndef __XFS_SUPPORT_MRLOCK_H__
7 #define __XFS_SUPPORT_MRLOCK_H__
9 #include <linux/rwsem.h>
11 typedef struct {
12 struct rw_semaphore mr_lock;
13 #if defined(DEBUG) || defined(XFS_WARN)
14 int mr_writer;
15 #endif
16 } mrlock_t;
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)
21 #else
22 #define mrinit(mrp, name) \
23 do { init_rwsem(&(mrp)->mr_lock); } while (0)
24 #endif
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)
38 mrp->mr_writer = 1;
39 #endif
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))
50 return 0;
51 #if defined(DEBUG) || defined(XFS_WARN)
52 mrp->mr_writer = 1;
53 #endif
54 return 1;
57 static inline void mrunlock_excl(mrlock_t *mrp)
59 #if defined(DEBUG) || defined(XFS_WARN)
60 mrp->mr_writer = 0;
61 #endif
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)
73 mrp->mr_writer = 0;
74 #endif
75 downgrade_write(&mrp->mr_lock);
78 #endif /* __XFS_SUPPORT_MRLOCK_H__ */