2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2006-06-08 22:57:01 -06:00
|
|
|
* Copyright (c) 2000-2006 Silicon Graphics, Inc.
|
2005-11-01 20:58:39 -07:00
|
|
|
* All Rights Reserved.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
2005-04-16 16:20:36 -06:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* 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.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* 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
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_SUPPORT_MRLOCK_H__
|
|
|
|
#define __XFS_SUPPORT_MRLOCK_H__
|
|
|
|
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct rw_semaphore mr_lock;
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
2005-04-16 16:20:36 -06:00
|
|
|
int mr_writer;
|
2008-04-22 01:34:00 -06:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
} mrlock_t;
|
|
|
|
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
2005-04-16 16:20:36 -06:00
|
|
|
#define mrinit(mrp, name) \
|
2006-06-08 22:57:01 -06:00
|
|
|
do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
|
2008-04-22 01:34:00 -06:00
|
|
|
#else
|
|
|
|
#define mrinit(mrp, name) \
|
|
|
|
do { init_rwsem(&(mrp)->mr_lock); } while (0)
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
|
|
|
|
#define mrfree(mrp) do { } while (0)
|
|
|
|
|
2007-05-07 21:50:19 -06:00
|
|
|
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);
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
2007-05-07 21:50:19 -06:00
|
|
|
mrp->mr_writer = 1;
|
2008-04-22 01:34:00 -06:00
|
|
|
#endif
|
2007-05-07 21:50:19 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
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;
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
2005-04-16 16:20:36 -06:00
|
|
|
mrp->mr_writer = 1;
|
2008-04-22 01:34:00 -06:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-22 01:34:00 -06:00
|
|
|
static inline void mrunlock_excl(mrlock_t *mrp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
|
|
|
mrp->mr_writer = 0;
|
|
|
|
#endif
|
|
|
|
up_write(&mrp->mr_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-04-22 01:34:00 -06:00
|
|
|
static inline void mrunlock_shared(mrlock_t *mrp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-22 01:34:00 -06:00
|
|
|
up_read(&mrp->mr_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-04-22 01:34:00 -06:00
|
|
|
static inline void mrdemote(mrlock_t *mrp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-22 01:34:00 -06:00
|
|
|
#ifdef DEBUG
|
|
|
|
mrp->mr_writer = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2008-04-22 01:34:00 -06:00
|
|
|
downgrade_write(&mrp->mr_lock);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#endif /* __XFS_SUPPORT_MRLOCK_H__ */
|