kern_rwlock.c (176076) | kern_rwlock.c (177843) |
---|---|
1/*- 2 * Copyright (c) 2006 John Baldwin <jhb@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 --- 18 unchanged lines hidden (view full) --- 27 * SUCH DAMAGE. 28 */ 29 30/* 31 * Machine independent bits of reader/writer lock implementation. 32 */ 33 34#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 John Baldwin <jhb@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 --- 18 unchanged lines hidden (view full) --- 27 * SUCH DAMAGE. 28 */ 29 30/* 31 * Machine independent bits of reader/writer lock implementation. 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 176076 2008-02-07 06:16:54Z jeff $"); | 35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 177843 2008-04-01 20:31:55Z attilio $"); |
36 37#include "opt_ddb.h" 38#include "opt_no_adaptive_rwlocks.h" 39 40#include <sys/param.h> 41#include <sys/ktr.h> 42#include <sys/lock.h> 43#include <sys/mutex.h> --- 154 unchanged lines hidden (view full) --- 198 WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, 199 line); 200 __rw_wlock(rw, curthread, file, line); 201 LOCK_LOG_LOCK("WLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line); 202 WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); 203 curthread->td_locks++; 204} 205 | 36 37#include "opt_ddb.h" 38#include "opt_no_adaptive_rwlocks.h" 39 40#include <sys/param.h> 41#include <sys/ktr.h> 42#include <sys/lock.h> 43#include <sys/mutex.h> --- 154 unchanged lines hidden (view full) --- 198 WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, 199 line); 200 __rw_wlock(rw, curthread, file, line); 201 LOCK_LOG_LOCK("WLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line); 202 WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); 203 curthread->td_locks++; 204} 205 |
206int 207_rw_try_wlock(struct rwlock *rw, const char *file, int line) 208{ 209 int rval; 210 211 KASSERT(rw->rw_lock != RW_DESTROYED, 212 ("rw_try_wlock() of destroyed rwlock @ %s:%d", file, line)); 213 214 if (rw_wlocked(rw) && (rw->lock_object.lo_flags & RW_RECURSE) != 0) { 215 rw->rw_recurse++; 216 rval = 1; 217 } else 218 rval = atomic_cmpset_acq_ptr(&rw->rw_lock, RW_UNLOCKED, 219 (uintptr_t)curthread); 220 221 LOCK_LOG_TRY("WLOCK", &rw->lock_object, 0, rval, file, line); 222 if (rval) { 223 WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE | LOP_TRYLOCK, 224 file, line); 225 curthread->td_locks++; 226 } 227 return (rval); 228} 229 |
|
206void 207_rw_wunlock(struct rwlock *rw, const char *file, int line) 208{ 209 210 MPASS(curthread != NULL); 211 KASSERT(rw->rw_lock != RW_DESTROYED, 212 ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line)); 213 _rw_assert(rw, RA_WLOCKED, file, line); --- 167 unchanged lines hidden (view full) --- 381 lock_profile_obtain_lock_success( &rw->lock_object, contested, 382 waittime, file, line); 383 LOCK_LOG_LOCK("RLOCK", &rw->lock_object, 0, 0, file, line); 384 WITNESS_LOCK(&rw->lock_object, 0, file, line); 385 curthread->td_locks++; 386 curthread->td_rw_rlocks++; 387} 388 | 230void 231_rw_wunlock(struct rwlock *rw, const char *file, int line) 232{ 233 234 MPASS(curthread != NULL); 235 KASSERT(rw->rw_lock != RW_DESTROYED, 236 ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line)); 237 _rw_assert(rw, RA_WLOCKED, file, line); --- 167 unchanged lines hidden (view full) --- 405 lock_profile_obtain_lock_success( &rw->lock_object, contested, 406 waittime, file, line); 407 LOCK_LOG_LOCK("RLOCK", &rw->lock_object, 0, 0, file, line); 408 WITNESS_LOCK(&rw->lock_object, 0, file, line); 409 curthread->td_locks++; 410 curthread->td_rw_rlocks++; 411} 412 |
413int 414_rw_try_rlock(struct rwlock *rw, const char *file, int line) 415{ 416 uintptr_t x; 417 418 for (;;) { 419 x = rw->rw_lock; 420 KASSERT(rw->rw_lock != RW_DESTROYED, 421 ("rw_try_rlock() of destroyed rwlock @ %s:%d", file, line)); 422 if (!(x & RW_LOCK_READ)) 423 break; 424 if (atomic_cmpset_acq_ptr(&rw->rw_lock, x, x + RW_ONE_READER)) { 425 LOCK_LOG_TRY("RLOCK", &rw->lock_object, 0, 1, file, 426 line); 427 WITNESS_LOCK(&rw->lock_object, LOP_TRYLOCK, file, line); 428 curthread->td_locks++; 429 curthread->td_rw_rlocks++; 430 return (1); 431 } 432 } 433 434 LOCK_LOG_TRY("RLOCK", &rw->lock_object, 0, 0, file, line); 435 return (0); 436} 437 |
|
389void 390_rw_runlock(struct rwlock *rw, const char *file, int line) 391{ 392 struct turnstile *ts; 393 uintptr_t x, v, queue; 394 395 KASSERT(rw->rw_lock != RW_DESTROYED, 396 ("rw_runlock() of destroyed rwlock @ %s:%d", file, line)); --- 560 unchanged lines hidden --- | 438void 439_rw_runlock(struct rwlock *rw, const char *file, int line) 440{ 441 struct turnstile *ts; 442 uintptr_t x, v, queue; 443 444 KASSERT(rw->rw_lock != RW_DESTROYED, 445 ("rw_runlock() of destroyed rwlock @ %s:%d", file, line)); --- 560 unchanged lines hidden --- |