kern_sx.c (154484) | kern_sx.c (160771) |
---|---|
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 --- 20 unchanged lines hidden (view full) --- 29 * Shared/exclusive locks. This implementation assures deterministic lock 30 * granting behavior, so that slocks and xlocks are interleaved. 31 * 32 * Priority propagation will not generally raise the priority of lock holders, 33 * so should not be relied upon in combination with sx locks. 34 */ 35 36#include <sys/cdefs.h> | 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 --- 20 unchanged lines hidden (view full) --- 29 * Shared/exclusive locks. This implementation assures deterministic lock 30 * granting behavior, so that slocks and xlocks are interleaved. 31 * 32 * Priority propagation will not generally raise the priority of lock holders, 33 * so should not be relied upon in combination with sx locks. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 154484 2006-01-17 16:55:17Z jhb $"); | 37__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 160771 2006-07-27 21:45:55Z jhb $"); |
38 39#include "opt_ddb.h" 40 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/ktr.h> 44#include <sys/linker_set.h> 45#include <sys/condvar.h> --- 77 unchanged lines hidden (view full) --- 123 sx->sx_shrd_wcnt--; 124 } 125 126 /* Acquire a shared lock. */ 127 sx->sx_cnt++; 128 129 LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line); 130 WITNESS_LOCK(&sx->sx_object, 0, file, line); | 38 39#include "opt_ddb.h" 40 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/ktr.h> 44#include <sys/linker_set.h> 45#include <sys/condvar.h> --- 77 unchanged lines hidden (view full) --- 123 sx->sx_shrd_wcnt--; 124 } 125 126 /* Acquire a shared lock. */ 127 sx->sx_cnt++; 128 129 LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line); 130 WITNESS_LOCK(&sx->sx_object, 0, file, line); |
131 curthread->td_locks++; |
|
131 132 mtx_unlock(sx->sx_lock); 133} 134 135int 136_sx_try_slock(struct sx *sx, const char *file, int line) 137{ 138 139 mtx_lock(sx->sx_lock); 140 if (sx->sx_cnt >= 0) { 141 sx->sx_cnt++; 142 LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 1, file, line); 143 WITNESS_LOCK(&sx->sx_object, LOP_TRYLOCK, file, line); | 132 133 mtx_unlock(sx->sx_lock); 134} 135 136int 137_sx_try_slock(struct sx *sx, const char *file, int line) 138{ 139 140 mtx_lock(sx->sx_lock); 141 if (sx->sx_cnt >= 0) { 142 sx->sx_cnt++; 143 LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 1, file, line); 144 WITNESS_LOCK(&sx->sx_object, LOP_TRYLOCK, file, line); |
145 curthread->td_locks++; |
|
144 mtx_unlock(sx->sx_lock); 145 return (1); 146 } else { 147 LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 0, file, line); 148 mtx_unlock(sx->sx_lock); 149 return (0); 150 } 151} --- 27 unchanged lines hidden (view full) --- 179 MPASS(sx->sx_cnt == 0); 180 181 /* Acquire an exclusive lock. */ 182 sx->sx_cnt--; 183 sx->sx_xholder = curthread; 184 185 LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line); 186 WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); | 146 mtx_unlock(sx->sx_lock); 147 return (1); 148 } else { 149 LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 0, file, line); 150 mtx_unlock(sx->sx_lock); 151 return (0); 152 } 153} --- 27 unchanged lines hidden (view full) --- 181 MPASS(sx->sx_cnt == 0); 182 183 /* Acquire an exclusive lock. */ 184 sx->sx_cnt--; 185 sx->sx_xholder = curthread; 186 187 LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line); 188 WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); |
189 curthread->td_locks++; |
|
187 188 mtx_unlock(sx->sx_lock); 189} 190 191int 192_sx_try_xlock(struct sx *sx, const char *file, int line) 193{ 194 195 mtx_lock(sx->sx_lock); 196 if (sx->sx_cnt == 0) { 197 sx->sx_cnt--; 198 sx->sx_xholder = curthread; 199 LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 1, file, line); 200 WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE | LOP_TRYLOCK, file, 201 line); | 190 191 mtx_unlock(sx->sx_lock); 192} 193 194int 195_sx_try_xlock(struct sx *sx, const char *file, int line) 196{ 197 198 mtx_lock(sx->sx_lock); 199 if (sx->sx_cnt == 0) { 200 sx->sx_cnt--; 201 sx->sx_xholder = curthread; 202 LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 1, file, line); 203 WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE | LOP_TRYLOCK, file, 204 line); |
205 curthread->td_locks++; |
|
202 mtx_unlock(sx->sx_lock); 203 return (1); 204 } else { 205 LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 0, file, line); 206 mtx_unlock(sx->sx_lock); 207 return (0); 208 } 209} 210 211void 212_sx_sunlock(struct sx *sx, const char *file, int line) 213{ 214 215 _sx_assert(sx, SX_SLOCKED, file, line); 216 mtx_lock(sx->sx_lock); 217 | 206 mtx_unlock(sx->sx_lock); 207 return (1); 208 } else { 209 LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 0, file, line); 210 mtx_unlock(sx->sx_lock); 211 return (0); 212 } 213} 214 215void 216_sx_sunlock(struct sx *sx, const char *file, int line) 217{ 218 219 _sx_assert(sx, SX_SLOCKED, file, line); 220 mtx_lock(sx->sx_lock); 221 |
222 curthread->td_locks--; |
|
218 WITNESS_UNLOCK(&sx->sx_object, 0, file, line); 219 220 /* Release. */ 221 sx->sx_cnt--; 222 223 /* 224 * If we just released the last shared lock, wake any waiters up, giving 225 * exclusive lockers precedence. In order to make sure that exclusive --- 14 unchanged lines hidden (view full) --- 240void 241_sx_xunlock(struct sx *sx, const char *file, int line) 242{ 243 244 _sx_assert(sx, SX_XLOCKED, file, line); 245 mtx_lock(sx->sx_lock); 246 MPASS(sx->sx_cnt == -1); 247 | 223 WITNESS_UNLOCK(&sx->sx_object, 0, file, line); 224 225 /* Release. */ 226 sx->sx_cnt--; 227 228 /* 229 * If we just released the last shared lock, wake any waiters up, giving 230 * exclusive lockers precedence. In order to make sure that exclusive --- 14 unchanged lines hidden (view full) --- 245void 246_sx_xunlock(struct sx *sx, const char *file, int line) 247{ 248 249 _sx_assert(sx, SX_XLOCKED, file, line); 250 mtx_lock(sx->sx_lock); 251 MPASS(sx->sx_cnt == -1); 252 |
253 curthread->td_locks--; |
|
248 WITNESS_UNLOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); 249 250 /* Release. */ 251 sx->sx_cnt++; 252 sx->sx_xholder = NULL; 253 254 /* 255 * Wake up waiters if there are any. Give precedence to slock waiters. --- 137 unchanged lines hidden --- | 254 WITNESS_UNLOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); 255 256 /* Release. */ 257 sx->sx_cnt++; 258 sx->sx_xholder = NULL; 259 260 /* 261 * Wake up waiters if there are any. Give precedence to slock waiters. --- 137 unchanged lines hidden --- |