Blame view

fs/xfs/mrlock.h 2.18 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
72c93bcc6   Ingo Molnar   [XFS] lock valida...
2
   * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b7187698   Nathan Scott   [XFS] Update lice...
3
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
7b7187698   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
7b7187698   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
7b7187698   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
21
   */
  #ifndef __XFS_SUPPORT_MRLOCK_H__
  #define __XFS_SUPPORT_MRLOCK_H__
  
  #include <linux/rwsem.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
  typedef struct {
  	struct rw_semaphore	mr_lock;
742ae1e35   Dave Chinner   xfs: introduce CO...
24
  #if defined(DEBUG) || defined(XFS_WARN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
  	int			mr_writer;
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
26
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  } mrlock_t;
742ae1e35   Dave Chinner   xfs: introduce CO...
28
  #if defined(DEBUG) || defined(XFS_WARN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  #define mrinit(mrp, name)	\
72c93bcc6   Ingo Molnar   [XFS] lock valida...
30
  	do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
31
32
33
34
  #else
  #define mrinit(mrp, name)	\
  	do { init_rwsem(&(mrp)->mr_lock); } while (0)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  #define mrlock_init(mrp, t,n,s)	mrinit(mrp, n)
  #define mrfree(mrp)		do { } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37

f7c66ce3f   Lachlan McIlroy   [XFS] Add lockdep...
38
39
40
41
42
43
44
45
  static inline void mraccess_nested(mrlock_t *mrp, int subclass)
  {
  	down_read_nested(&mrp->mr_lock, subclass);
  }
  
  static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
  {
  	down_write_nested(&mrp->mr_lock, subclass);
742ae1e35   Dave Chinner   xfs: introduce CO...
46
  #if defined(DEBUG) || defined(XFS_WARN)
f7c66ce3f   Lachlan McIlroy   [XFS] Add lockdep...
47
  	mrp->mr_writer = 1;
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
48
  #endif
f7c66ce3f   Lachlan McIlroy   [XFS] Add lockdep...
49
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
53
54
55
56
57
58
  static inline int mrtryaccess(mrlock_t *mrp)
  {
  	return down_read_trylock(&mrp->mr_lock);
  }
  
  static inline int mrtryupdate(mrlock_t *mrp)
  {
  	if (!down_write_trylock(&mrp->mr_lock))
  		return 0;
742ae1e35   Dave Chinner   xfs: introduce CO...
59
  #if defined(DEBUG) || defined(XFS_WARN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  	mrp->mr_writer = 1;
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
61
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
  	return 1;
  }
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
64
  static inline void mrunlock_excl(mrlock_t *mrp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
  {
742ae1e35   Dave Chinner   xfs: introduce CO...
66
  #if defined(DEBUG) || defined(XFS_WARN)
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
67
68
69
  	mrp->mr_writer = 0;
  #endif
  	up_write(&mrp->mr_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
  }
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
71
  static inline void mrunlock_shared(mrlock_t *mrp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  {
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
73
  	up_read(&mrp->mr_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  }
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
75
  static inline void mrdemote(mrlock_t *mrp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  {
742ae1e35   Dave Chinner   xfs: introduce CO...
77
  #if defined(DEBUG) || defined(XFS_WARN)
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
78
  	mrp->mr_writer = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  #endif
579aa9caf   Christoph Hellwig   [XFS] shrink mrlo...
80
81
  	downgrade_write(&mrp->mr_lock);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
  
  #endif /* __XFS_SUPPORT_MRLOCK_H__ */