kern_sx.c (86333) | kern_sx.c (87594) |
---|---|
1/* 2 * Copyright (C) 2001 Jason Evans <jasone@freebsd.org>. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice(s), this list of conditions and the following disclaimer as --- 10 unchanged lines hidden (view full) --- 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 * DAMAGE. 26 * | 1/* 2 * Copyright (C) 2001 Jason Evans <jasone@freebsd.org>. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice(s), this list of conditions and the following disclaimer as --- 10 unchanged lines hidden (view full) --- 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 * DAMAGE. 26 * |
27 * $FreeBSD: head/sys/kern/kern_sx.c 86333 2001-11-13 21:55:13Z dillon $ | 27 * $FreeBSD: head/sys/kern/kern_sx.c 87594 2001-12-10 05:51:45Z obrien $ |
28 */ 29 30/* 31 * Shared/exclusive locks. This implementation assures deterministic lock 32 * granting behavior, so that slocks and xlocks are interleaved. 33 * 34 * Priority propagation will not generally raise the priority of lock holders, 35 * so should not be relied upon in combination with sx locks. --- 44 unchanged lines hidden (view full) --- 80 81void 82sx_destroy(struct sx *sx) 83{ 84 85 LOCK_LOG_DESTROY(&sx->sx_object, 0); 86 87 KASSERT((sx->sx_cnt == 0 && sx->sx_shrd_wcnt == 0 && sx->sx_excl_wcnt == | 28 */ 29 30/* 31 * Shared/exclusive locks. This implementation assures deterministic lock 32 * granting behavior, so that slocks and xlocks are interleaved. 33 * 34 * Priority propagation will not generally raise the priority of lock holders, 35 * so should not be relied upon in combination with sx locks. --- 44 unchanged lines hidden (view full) --- 80 81void 82sx_destroy(struct sx *sx) 83{ 84 85 LOCK_LOG_DESTROY(&sx->sx_object, 0); 86 87 KASSERT((sx->sx_cnt == 0 && sx->sx_shrd_wcnt == 0 && sx->sx_excl_wcnt == |
88 0), ("%s (%s): holders or waiters\n", __FUNCTION__, | 88 0), ("%s (%s): holders or waiters\n", __func__, |
89 sx->sx_object.lo_name)); 90 91 sx->sx_lock = NULL; 92 cv_destroy(&sx->sx_shrd_cv); 93 cv_destroy(&sx->sx_excl_cv); 94 95 WITNESS_DESTROY(&sx->sx_object); 96} 97 98void 99_sx_slock(struct sx *sx, const char *file, int line) 100{ 101 102 mtx_lock(sx->sx_lock); 103 KASSERT(sx->sx_xholder != curthread, | 89 sx->sx_object.lo_name)); 90 91 sx->sx_lock = NULL; 92 cv_destroy(&sx->sx_shrd_cv); 93 cv_destroy(&sx->sx_excl_cv); 94 95 WITNESS_DESTROY(&sx->sx_object); 96} 97 98void 99_sx_slock(struct sx *sx, const char *file, int line) 100{ 101 102 mtx_lock(sx->sx_lock); 103 KASSERT(sx->sx_xholder != curthread, |
104 ("%s (%s): slock while xlock is held @ %s:%d\n", __FUNCTION__, | 104 ("%s (%s): slock while xlock is held @ %s:%d\n", __func__, |
105 sx->sx_object.lo_name, file, line)); 106 107 /* 108 * Loop in case we lose the race for lock acquisition. 109 */ 110 while (sx->sx_cnt < 0) { 111 sx->sx_shrd_wcnt++; 112 cv_wait(&sx->sx_shrd_cv, sx->sx_lock); --- 36 unchanged lines hidden (view full) --- 149 /* 150 * With sx locks, we're absolutely not permitted to recurse on 151 * xlocks, as it is fatal (deadlock). Normally, recursion is handled 152 * by WITNESS, but as it is not semantically correct to hold the 153 * xlock while in here, we consider it API abuse and put it under 154 * INVARIANTS. 155 */ 156 KASSERT(sx->sx_xholder != curthread, | 105 sx->sx_object.lo_name, file, line)); 106 107 /* 108 * Loop in case we lose the race for lock acquisition. 109 */ 110 while (sx->sx_cnt < 0) { 111 sx->sx_shrd_wcnt++; 112 cv_wait(&sx->sx_shrd_cv, sx->sx_lock); --- 36 unchanged lines hidden (view full) --- 149 /* 150 * With sx locks, we're absolutely not permitted to recurse on 151 * xlocks, as it is fatal (deadlock). Normally, recursion is handled 152 * by WITNESS, but as it is not semantically correct to hold the 153 * xlock while in here, we consider it API abuse and put it under 154 * INVARIANTS. 155 */ 156 KASSERT(sx->sx_xholder != curthread, |
157 ("%s (%s): xlock already held @ %s:%d", __FUNCTION__, | 157 ("%s (%s): xlock already held @ %s:%d", __func__, |
158 sx->sx_object.lo_name, file, line)); 159 160 /* Loop in case we lose the race for lock acquisition. */ 161 while (sx->sx_cnt != 0) { 162 sx->sx_excl_wcnt++; 163 cv_wait(&sx->sx_excl_cv, sx->sx_lock); 164 sx->sx_excl_wcnt--; 165 } --- 175 unchanged lines hidden --- | 158 sx->sx_object.lo_name, file, line)); 159 160 /* Loop in case we lose the race for lock acquisition. */ 161 while (sx->sx_cnt != 0) { 162 sx->sx_excl_wcnt++; 163 cv_wait(&sx->sx_excl_cv, sx->sx_lock); 164 sx->sx_excl_wcnt--; 165 } --- 175 unchanged lines hidden --- |