]> git.ipfire.org Git - people/ms/linux.git/blame - fs/xfs/mrlock.h
Merge tag 'soc-fixes-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[people/ms/linux.git] / fs / xfs / mrlock.h
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
72c93bcc 3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b718769 4 * All Rights Reserved.
1da177e4
LT
5 */
6#ifndef __XFS_SUPPORT_MRLOCK_H__
7#define __XFS_SUPPORT_MRLOCK_H__
8
9#include <linux/rwsem.h>
10
1da177e4
LT
11typedef struct {
12 struct rw_semaphore mr_lock;
742ae1e3 13#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 14 int mr_writer;
579aa9ca 15#endif
1da177e4
LT
16} mrlock_t;
17
742ae1e3 18#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 19#define mrinit(mrp, name) \
72c93bcc 20 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
579aa9ca
CH
21#else
22#define mrinit(mrp, name) \
23 do { init_rwsem(&(mrp)->mr_lock); } while (0)
24#endif
25
1da177e4
LT
26#define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
27#define mrfree(mrp) do { } while (0)
1da177e4 28
f7c66ce3
LM
29static inline void mraccess_nested(mrlock_t *mrp, int subclass)
30{
31 down_read_nested(&mrp->mr_lock, subclass);
32}
33
34static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
35{
36 down_write_nested(&mrp->mr_lock, subclass);
742ae1e3 37#if defined(DEBUG) || defined(XFS_WARN)
f7c66ce3 38 mrp->mr_writer = 1;
579aa9ca 39#endif
f7c66ce3
LM
40}
41
1da177e4
LT
42static inline int mrtryaccess(mrlock_t *mrp)
43{
44 return down_read_trylock(&mrp->mr_lock);
45}
46
47static inline int mrtryupdate(mrlock_t *mrp)
48{
49 if (!down_write_trylock(&mrp->mr_lock))
50 return 0;
742ae1e3 51#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 52 mrp->mr_writer = 1;
579aa9ca 53#endif
1da177e4
LT
54 return 1;
55}
56
579aa9ca 57static inline void mrunlock_excl(mrlock_t *mrp)
1da177e4 58{
742ae1e3 59#if defined(DEBUG) || defined(XFS_WARN)
579aa9ca
CH
60 mrp->mr_writer = 0;
61#endif
62 up_write(&mrp->mr_lock);
1da177e4
LT
63}
64
579aa9ca 65static inline void mrunlock_shared(mrlock_t *mrp)
1da177e4 66{
579aa9ca 67 up_read(&mrp->mr_lock);
1da177e4
LT
68}
69
579aa9ca 70static inline void mrdemote(mrlock_t *mrp)
1da177e4 71{
742ae1e3 72#if defined(DEBUG) || defined(XFS_WARN)
579aa9ca 73 mrp->mr_writer = 0;
1da177e4 74#endif
579aa9ca
CH
75 downgrade_write(&mrp->mr_lock);
76}
1da177e4
LT
77
78#endif /* __XFS_SUPPORT_MRLOCK_H__ */