disable some mediatekl custom warnings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / xfs / mrlock.h
CommitLineData
1da177e4 1/*
72c93bcc 2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b718769 3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
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
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
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.
1da177e4 13 *
7b718769
NS
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
1da177e4
LT
17 */
18#ifndef __XFS_SUPPORT_MRLOCK_H__
19#define __XFS_SUPPORT_MRLOCK_H__
20
21#include <linux/rwsem.h>
22
1da177e4
LT
23typedef struct {
24 struct rw_semaphore mr_lock;
742ae1e3 25#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 26 int mr_writer;
579aa9ca 27#endif
1da177e4
LT
28} mrlock_t;
29
742ae1e3 30#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 31#define mrinit(mrp, name) \
72c93bcc 32 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
579aa9ca
CH
33#else
34#define mrinit(mrp, name) \
35 do { init_rwsem(&(mrp)->mr_lock); } while (0)
36#endif
37
1da177e4
LT
38#define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
39#define mrfree(mrp) do { } while (0)
1da177e4 40
f7c66ce3
LM
41static inline void mraccess_nested(mrlock_t *mrp, int subclass)
42{
43 down_read_nested(&mrp->mr_lock, subclass);
44}
45
46static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
47{
48 down_write_nested(&mrp->mr_lock, subclass);
742ae1e3 49#if defined(DEBUG) || defined(XFS_WARN)
f7c66ce3 50 mrp->mr_writer = 1;
579aa9ca 51#endif
f7c66ce3
LM
52}
53
1da177e4
LT
54static inline int mrtryaccess(mrlock_t *mrp)
55{
56 return down_read_trylock(&mrp->mr_lock);
57}
58
59static inline int mrtryupdate(mrlock_t *mrp)
60{
61 if (!down_write_trylock(&mrp->mr_lock))
62 return 0;
742ae1e3 63#if defined(DEBUG) || defined(XFS_WARN)
1da177e4 64 mrp->mr_writer = 1;
579aa9ca 65#endif
1da177e4
LT
66 return 1;
67}
68
579aa9ca 69static inline void mrunlock_excl(mrlock_t *mrp)
1da177e4 70{
742ae1e3 71#if defined(DEBUG) || defined(XFS_WARN)
579aa9ca
CH
72 mrp->mr_writer = 0;
73#endif
74 up_write(&mrp->mr_lock);
1da177e4
LT
75}
76
579aa9ca 77static inline void mrunlock_shared(mrlock_t *mrp)
1da177e4 78{
579aa9ca 79 up_read(&mrp->mr_lock);
1da177e4
LT
80}
81
579aa9ca 82static inline void mrdemote(mrlock_t *mrp)
1da177e4 83{
742ae1e3 84#if defined(DEBUG) || defined(XFS_WARN)
579aa9ca 85 mrp->mr_writer = 0;
1da177e4 86#endif
579aa9ca
CH
87 downgrade_write(&mrp->mr_lock);
88}
1da177e4
LT
89
90#endif /* __XFS_SUPPORT_MRLOCK_H__ */