sx.h revision 85388
173782Sjasone/* 273782Sjasone * Copyright (C) 2001 Jason Evans <jasone@freebsd.org>. All rights reserved. 373782Sjasone * 473782Sjasone * Redistribution and use in source and binary forms, with or without 573782Sjasone * modification, are permitted provided that the following conditions 673782Sjasone * are met: 773782Sjasone * 1. Redistributions of source code must retain the above copyright 873782Sjasone * notice(s), this list of conditions and the following disclaimer as 973782Sjasone * the first lines of this file unmodified other than the possible 1073782Sjasone * addition of one or more copyright notices. 1173782Sjasone * 2. Redistributions in binary form must reproduce the above copyright 1273782Sjasone * notice(s), this list of conditions and the following disclaimer in the 1373782Sjasone * documentation and/or other materials provided with the distribution. 1473782Sjasone * 1573782Sjasone * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1673782Sjasone * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1773782Sjasone * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1873782Sjasone * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 1973782Sjasone * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2073782Sjasone * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2173782Sjasone * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 2273782Sjasone * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2373782Sjasone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2473782Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 2573782Sjasone * DAMAGE. 2673782Sjasone * 2773782Sjasone * $FreeBSD: head/sys/sys/sx.h 85388 2001-10-23 22:39:11Z jhb $ 2873782Sjasone */ 2973782Sjasone 3073782Sjasone#ifndef _SYS_SX_H_ 3173782Sjasone#define _SYS_SX_H_ 3273782Sjasone 3373782Sjasone#ifndef LOCORE 3483103Sjhb#include <sys/_lock.h> 3576166Smarkm#include <sys/_mutex.h> 3674912Sjhb#include <sys/condvar.h> /* XXX */ 3773782Sjasone 3873782Sjasonestruct sx { 3974912Sjhb struct lock_object sx_object; /* Common lock properties. */ 4073863Sbmilekic struct mtx sx_lock; /* General protection lock. */ 4173782Sjasone int sx_cnt; /* -1: xlock, > 0: slock count. */ 4273782Sjasone struct cv sx_shrd_cv; /* slock waiters. */ 4373782Sjasone int sx_shrd_wcnt; /* Number of slock waiters. */ 4473782Sjasone struct cv sx_excl_cv; /* xlock waiters. */ 4573782Sjasone int sx_excl_wcnt; /* Number of xlock waiters. */ 4683366Sjulian struct thread *sx_xholder; /* Thread presently holding xlock. */ 4773782Sjasone}; 4873782Sjasone 4973782Sjasone#ifdef _KERNEL 5073782Sjasonevoid sx_init(struct sx *sx, const char *description); 5173782Sjasonevoid sx_destroy(struct sx *sx); 5274912Sjhbvoid _sx_slock(struct sx *sx, const char *file, int line); 5374912Sjhbvoid _sx_xlock(struct sx *sx, const char *file, int line); 5478872Sjhbint _sx_try_slock(struct sx *sx, const char *file, int line); 5578872Sjhbint _sx_try_xlock(struct sx *sx, const char *file, int line); 5674912Sjhbvoid _sx_sunlock(struct sx *sx, const char *file, int line); 5774912Sjhbvoid _sx_xunlock(struct sx *sx, const char *file, int line); 5881599Sjasoneint _sx_try_upgrade(struct sx *sx, const char *file, int line); 5981599Sjasonevoid _sx_downgrade(struct sx *sx, const char *file, int line); 6085388Sjhb#ifdef INVARIANT_SUPPORT 6185388Sjhbvoid _sx_assert(struct sx *sx, int what, const char *file, int line); 6285388Sjhb#endif 6373782Sjasone 6483593Sjhb#define sx_slock(sx) _sx_slock((sx), LOCK_FILE, LOCK_LINE) 6583593Sjhb#define sx_xlock(sx) _sx_xlock((sx), LOCK_FILE, LOCK_LINE) 6683593Sjhb#define sx_try_slock(sx) _sx_try_slock((sx), LOCK_FILE, LOCK_LINE) 6783593Sjhb#define sx_try_xlock(sx) _sx_try_xlock((sx), LOCK_FILE, LOCK_LINE) 6883593Sjhb#define sx_sunlock(sx) _sx_sunlock((sx), LOCK_FILE, LOCK_LINE) 6983593Sjhb#define sx_xunlock(sx) _sx_xunlock((sx), LOCK_FILE, LOCK_LINE) 7083593Sjhb#define sx_try_upgrade(sx) _sx_try_upgrade((sx), LOCK_FILE, LOCK_LINE) 7183593Sjhb#define sx_downgrade(sx) _sx_downgrade((sx), LOCK_FILE, LOCK_LINE) 7274912Sjhb 7373782Sjasone#ifdef INVARIANTS 7485388Sjhb#define SX_LOCKED LA_LOCKED 7585388Sjhb#define SX_SLOCKED LA_SLOCKED 7685388Sjhb#define SX_XLOCKED LA_XLOCKED 7773863Sbmilekic 7885388Sjhb#define sx_assert(sx, what) _sx_assert((sx), (what), LOCK_FILE, LOCK_LINE) 7973782Sjasone#else /* INVARIANTS */ 8085388Sjhb#define sx_assert(sx, what) 8173782Sjasone#endif /* INVARIANTS */ 8273782Sjasone 8373782Sjasone#endif /* _KERNEL */ 8473782Sjasone#endif /* !LOCORE */ 8573782Sjasone#endif /* _SYS_SX_H_ */ 86