2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_SUPPORT_MRLOCK_H__
33 #define __XFS_SUPPORT_MRLOCK_H__
35 #include <linux/time.h>
36 #include <linux/wait.h>
37 #include <asm/atomic.h>
38 #include <asm/semaphore.h>
41 * Implement mrlocks on Linux that work for XFS.
43 * These are sleep locks and not spinlocks. If one wants read/write spinlocks,
44 * use read_lock, write_lock, ... see spinlock.h.
47 typedef struct mrlock_s {
49 unsigned short mr_reads_waiting;
50 unsigned short mr_writes_waiting;
51 wait_queue_head_t mr_readerq;
52 wait_queue_head_t mr_writerq;
59 #define MRLOCK_BARRIER 0x1
60 #define MRLOCK_ALLOW_EQUAL_PRI 0x8
63 * mraccessf/mrupdatef take flags to be passed in while sleeping;
64 * only PLTWAIT is currently supported.
67 extern void mraccessf(mrlock_t *, int);
68 extern void mrupdatef(mrlock_t *, int);
69 extern void mrlock(mrlock_t *, int, int);
70 extern void mrunlock(mrlock_t *);
71 extern void mraccunlock(mrlock_t *);
72 extern int mrtryupdate(mrlock_t *);
73 extern int mrtryaccess(mrlock_t *);
74 extern int mrtrypromote(mrlock_t *);
75 extern void mrdemote(mrlock_t *);
77 extern int ismrlocked(mrlock_t *, int);
78 extern void mrlock_init(mrlock_t *, int type, char *name, long sequence);
79 extern void mrfree(mrlock_t *);
81 #define mrinit(mrp, name) mrlock_init(mrp, MRLOCK_BARRIER, name, -1)
82 #define mraccess(mrp) mraccessf(mrp, 0) /* grab for READ/ACCESS */
83 #define mrupdate(mrp) mrupdatef(mrp, 0) /* grab for WRITE/UPDATE */
84 #define mrislocked_access(mrp) ((mrp)->mr_count > 0)
85 #define mrislocked_update(mrp) ((mrp)->mr_count < 0)
87 #endif /* __XFS_SUPPORT_MRLOCK_H__ */