rmlock.h revision 193026
1/*- 2 * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: head/sys/sys/rmlock.h 193026 2009-05-29 09:40:57Z rwatson $ 30 */ 31 32#ifndef _SYS_RMLOCK_H_ 33#define _SYS_RMLOCK_H_ 34 35#include <sys/mutex.h> 36#include <sys/_lock.h> 37#include <sys/_rmlock.h> 38 39#ifdef _KERNEL 40 41void rm_init(struct rmlock *rm, const char *name, int opts); 42void rm_destroy(struct rmlock *rm); 43int rm_wowned(struct rmlock *rm); 44void rm_sysinit(void *arg); 45 46void _rm_wlock_debug(struct rmlock *rm, const char *file, int line); 47void _rm_wunlock_debug(struct rmlock *rm, const char *file, int line); 48void _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker, 49 const char *file, int line); 50void _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker, 51 const char *file, int line); 52 53void _rm_wlock(struct rmlock *rm); 54void _rm_wunlock(struct rmlock *rm); 55void _rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker); 56void _rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker); 57 58/* 59 * Public interface for lock operations. 60 */ 61#ifndef LOCK_DEBUG 62#error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/rmlock.h> 63#endif 64 65#if LOCK_DEBUG > 0 66#define rm_wlock(rm) _rm_wlock_debug((rm), LOCK_FILE, LOCK_LINE) 67#define rm_wunlock(rm) _rm_wunlock_debug((rm), LOCK_FILE, LOCK_LINE) 68#define rm_rlock(rm,tracker) \ 69 _rm_rlock_debug((rm),(tracker), LOCK_FILE, LOCK_LINE ) 70#define rm_runlock(rm,tracker) \ 71 _rm_runlock_debug((rm), (tracker), LOCK_FILE, LOCK_LINE ) 72#else 73#define rm_wlock(rm) _rm_wlock((rm)) 74#define rm_wunlock(rm) _rm_wunlock((rm)) 75#define rm_rlock(rm,tracker) _rm_rlock((rm),(tracker)) 76#define rm_runlock(rm,tracker) _rm_runlock((rm), (tracker)) 77#endif 78 79struct rm_args { 80 struct rmlock *ra_rm; 81 const char *ra_desc; 82 int ra_opts; 83}; 84 85#define RM_SYSINIT(name, rm, desc, opts) \ 86 static struct rm_args name##_args = { \ 87 (rm), \ 88 (desc), \ 89 (opts), \ 90 }; \ 91 SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ 92 rm_sysinit, &name##_args); \ 93 SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ 94 rm_destroy, (rm)) 95 96#endif /* _KERNEL */ 97#endif /* !_SYS_RMLOCK_H_ */ 98