2018-06-06 09:42:14 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2006-06-09 11:57:01 +07:00
|
|
|
* Copyright (c) 2000-2006 Silicon Graphics, Inc.
|
2005-11-02 10:58:39 +07:00
|
|
|
* All Rights Reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_SUPPORT_MRLOCK_H__
|
|
|
|
#define __XFS_SUPPORT_MRLOCK_H__
|
|
|
|
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct rw_semaphore mr_lock;
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2005-04-17 05:20:36 +07:00
|
|
|
int mr_writer;
|
2008-04-22 14:34:00 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
} mrlock_t;
|
|
|
|
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define mrinit(mrp, name) \
|
2006-06-09 11:57:01 +07:00
|
|
|
do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
|
2008-04-22 14:34:00 +07:00
|
|
|
#else
|
|
|
|
#define mrinit(mrp, name) \
|
|
|
|
do { init_rwsem(&(mrp)->mr_lock); } while (0)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
|
|
|
|
#define mrfree(mrp) do { } while (0)
|
|
|
|
|
2007-05-08 10:50:19 +07: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);
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2007-05-08 10:50:19 +07:00
|
|
|
mrp->mr_writer = 1;
|
2008-04-22 14:34:00 +07:00
|
|
|
#endif
|
2007-05-08 10:50:19 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07: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;
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2005-04-17 05:20:36 +07:00
|
|
|
mrp->mr_writer = 1;
|
2008-04-22 14:34:00 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-22 14:34:00 +07:00
|
|
|
static inline void mrunlock_excl(mrlock_t *mrp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2008-04-22 14:34:00 +07:00
|
|
|
mrp->mr_writer = 0;
|
|
|
|
#endif
|
|
|
|
up_write(&mrp->mr_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-04-22 14:34:00 +07:00
|
|
|
static inline void mrunlock_shared(mrlock_t *mrp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-04-22 14:34:00 +07:00
|
|
|
up_read(&mrp->mr_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-04-22 14:34:00 +07:00
|
|
|
static inline void mrdemote(mrlock_t *mrp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-04-30 18:39:34 +07:00
|
|
|
#if defined(DEBUG) || defined(XFS_WARN)
|
2008-04-22 14:34:00 +07:00
|
|
|
mrp->mr_writer = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
2008-04-22 14:34:00 +07:00
|
|
|
downgrade_write(&mrp->mr_lock);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#endif /* __XFS_SUPPORT_MRLOCK_H__ */
|