1173444Sups/*- 2173444Sups * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org> 3173444Sups * All rights reserved. 4173444Sups * 5173444Sups * Redistribution and use in source and binary forms, with or without 6173444Sups * modification, are permitted provided that the following conditions 7173444Sups * are met: 8173444Sups * 1. Redistributions of source code must retain the above copyright 9173444Sups * notice, this list of conditions and the following disclaimer. 10173444Sups * 2. Redistributions in binary form must reproduce the above copyright 11173444Sups * notice, this list of conditions and the following disclaimer in the 12173444Sups * documentation and/or other materials provided with the distribution. 13173444Sups * 3. Neither the name of the author nor the names of any co-contributors 14173444Sups * may be used to endorse or promote products derived from this software 15173444Sups * without specific prior written permission. 16173444Sups * 17173444Sups * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18173444Sups * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19173444Sups * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20173444Sups * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21173444Sups * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22173444Sups * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23173444Sups * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24173444Sups * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25173444Sups * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26173444Sups * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27173444Sups * SUCH DAMAGE. 28173444Sups * 29173444Sups * $FreeBSD$ 30173444Sups */ 31173444Sups 32173444Sups#ifndef _SYS__RMLOCK_H_ 33173444Sups#define _SYS__RMLOCK_H_ 34173444Sups 35173444Sups/* 36173444Sups * Mostly reader/occasional writer lock. 37173444Sups */ 38173444Sups 39173444SupsLIST_HEAD(rmpriolist,rm_priotracker); 40173444Sups 41240624Sattiliostruct rm_queue { 42240624Sattilio struct rm_queue *volatile rmq_next; 43240624Sattilio struct rm_queue *volatile rmq_prev; 44240624Sattilio}; 45240624Sattilio 46173444Supsstruct rmlock { 47252209Sjhb struct lock_object lock_object; 48222813Sattilio volatile cpuset_t rm_writecpus; 49173444Sups LIST_HEAD(,rm_priotracker) rm_activeReaders; 50212112Smlaier union { 51252209Sjhb struct lock_object _rm_wlock_object; 52212112Smlaier struct mtx _rm_lock_mtx; 53212112Smlaier struct sx _rm_lock_sx; 54212112Smlaier } _rm_lock; 55173444Sups}; 56252209Sjhb 57252209Sjhb#define rm_wlock_object _rm_lock._rm_wlock_object 58212112Smlaier#define rm_lock_mtx _rm_lock._rm_lock_mtx 59212112Smlaier#define rm_lock_sx _rm_lock._rm_lock_sx 60173444Sups 61173444Supsstruct rm_priotracker { 62173444Sups struct rm_queue rmp_cpuQueue; /* Must be first */ 63173444Sups struct rmlock *rmp_rmlock; 64173444Sups struct thread *rmp_thread; 65173444Sups int rmp_flags; 66173444Sups LIST_ENTRY(rm_priotracker) rmp_qentry; 67173444Sups}; 68173444Sups 69173444Sups#endif /* !_SYS__RMLOCK_H_ */ 70