rwlock.h revision 328653
1323124Sdes/*-
257429Smarkm * Copyright (c) 2010 Isilon Systems, Inc.
357429Smarkm * Copyright (c) 2010 iX Systems, Inc.
457429Smarkm * Copyright (c) 2010 Panasas, Inc.
557429Smarkm * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
657429Smarkm * All rights reserved.
757429Smarkm *
857429Smarkm * Redistribution and use in source and binary forms, with or without
960573Skris * modification, are permitted provided that the following conditions
1065668Skris * are met:
1165668Skris * 1. Redistributions of source code must retain the above copyright
1265668Skris *    notice unmodified, this list of conditions, and the following
1365668Skris *    disclaimer.
1465668Skris * 2. Redistributions in binary form must reproduce the above copyright
1557429Smarkm *    notice, this list of conditions and the following disclaimer in the
1657429Smarkm *    documentation and/or other materials provided with the distribution.
1757429Smarkm *
1857429Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19162852Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20162852Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21162852Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22162852Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23162852Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24162852Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25162852Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26162852Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27162852Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28162852Sdes *
29181111Sdes * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/rwlock.h 328653 2018-02-01 13:01:44Z hselasky $
30181111Sdes */
31162852Sdes#ifndef	_LINUX_RWLOCK_H_
3257429Smarkm#define	_LINUX_RWLOCK_H_
3357429Smarkm
3476259Sgreen#include <sys/types.h>
3576259Sgreen#include <sys/lock.h>
36295367Sdes#include <sys/rwlock.h>
37323124Sdes#include <sys/libkern.h>
38323124Sdes
3957429Smarkmtypedef struct {
4076259Sgreen	struct rwlock rw;
41323124Sdes} rwlock_t;
42162852Sdes
4376259Sgreen#define	read_lock(_l)		rw_rlock(&(_l)->rw)
4457429Smarkm#define	write_lock(_l)		rw_wlock(&(_l)->rw)
4576259Sgreen#define	read_unlock(_l)		rw_runlock(&(_l)->rw)
4676259Sgreen#define	write_unlock(_l)	rw_wunlock(&(_l)->rw)
4798675Sdes#define	read_lock_irq(lock)	read_lock((lock))
4876259Sgreen#define	read_unlock_irq(lock)	read_unlock((lock))
4957429Smarkm#define	write_lock_irq(lock)	write_lock((lock))
5057429Smarkm#define	write_unlock_irq(lock)	write_unlock((lock))
5157429Smarkm#define	read_lock_irqsave(lock, flags)   				\
5257429Smarkm    do {(flags) = 0; read_lock(lock); } while (0)
5357429Smarkm#define	write_lock_irqsave(lock, flags)   				\
5457429Smarkm    do {(flags) = 0; write_lock(lock); } while (0)
5592555Sdes#define	read_unlock_irqrestore(lock, flags)				\
5657429Smarkm    do { read_unlock(lock); } while (0)
5757429Smarkm#define	write_unlock_irqrestore(lock, flags)				\
5857429Smarkm    do { write_unlock(lock); } while (0)
5957429Smarkm
6057429Smarkmstatic inline void
61295367Sdesrwlock_init(rwlock_t *lock)
62295367Sdes{
63181111Sdes
64181111Sdes	memset(&lock->rw, 0, sizeof(lock->rw));
6557429Smarkm	rw_init_flags(&lock->rw, "lnxrw", RW_NOWITNESS);
6657429Smarkm}
67181111Sdes
6857429Smarkm#endif	/* _LINUX_RWLOCK_H_ */
69181111Sdes