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