kern_rwlock.c (251323) | kern_rwlock.c (252212) |
---|---|
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 251323 2013-06-03 17:38:57Z jhb $"); | 35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 252212 2013-06-25 20:23:08Z jhb $"); |
36 37#include "opt_ddb.h" 38#include "opt_hwpmc_hooks.h" 39#include "opt_kdtrace.h" 40#include "opt_no_adaptive_rwlocks.h" 41 42#include <sys/param.h> 43#include <sys/kdb.h> --- 158 unchanged lines hidden (view full) --- 202 flags |= LO_NOPROFILE; 203 if (!(opts & RW_NOWITNESS)) 204 flags |= LO_WITNESS; 205 if (opts & RW_RECURSE) 206 flags |= LO_RECURSABLE; 207 if (opts & RW_QUIET) 208 flags |= LO_QUIET; 209 | 36 37#include "opt_ddb.h" 38#include "opt_hwpmc_hooks.h" 39#include "opt_kdtrace.h" 40#include "opt_no_adaptive_rwlocks.h" 41 42#include <sys/param.h> 43#include <sys/kdb.h> --- 158 unchanged lines hidden (view full) --- 202 flags |= LO_NOPROFILE; 203 if (!(opts & RW_NOWITNESS)) 204 flags |= LO_WITNESS; 205 if (opts & RW_RECURSE) 206 flags |= LO_RECURSABLE; 207 if (opts & RW_QUIET) 208 flags |= LO_QUIET; 209 |
210 lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); |
|
210 rw->rw_lock = RW_UNLOCKED; 211 rw->rw_recurse = 0; | 211 rw->rw_lock = RW_UNLOCKED; 212 rw->rw_recurse = 0; |
212 lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); | |
213} 214 215void 216_rw_destroy(volatile uintptr_t *c) 217{ 218 struct rwlock *rw; 219 220 rw = rwlock2rw(c); --- 93 unchanged lines hidden (view full) --- 314 if (SCHEDULER_STOPPED()) 315 return; 316 317 rw = rwlock2rw(c); 318 319 KASSERT(rw->rw_lock != RW_DESTROYED, 320 ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line)); 321 __rw_assert(c, RA_WLOCKED, file, line); | 213} 214 215void 216_rw_destroy(volatile uintptr_t *c) 217{ 218 struct rwlock *rw; 219 220 rw = rwlock2rw(c); --- 93 unchanged lines hidden (view full) --- 314 if (SCHEDULER_STOPPED()) 315 return; 316 317 rw = rwlock2rw(c); 318 319 KASSERT(rw->rw_lock != RW_DESTROYED, 320 ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line)); 321 __rw_assert(c, RA_WLOCKED, file, line); |
322 curthread->td_locks--; | |
323 WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); 324 LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file, 325 line); 326 if (!rw_recursed(rw)) 327 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_WUNLOCK_RELEASE, rw); 328 __rw_wunlock(rw, curthread, file, line); | 322 WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); 323 LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file, 324 line); 325 if (!rw_recursed(rw)) 326 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_WUNLOCK_RELEASE, rw); 327 __rw_wunlock(rw, curthread, file, line); |
328 curthread->td_locks--; |
|
329} 330/* 331 * Determines whether a new reader can acquire a lock. Succeeds if the 332 * reader already owns a read lock and the lock is locked for read to 333 * prevent deadlock from reader recursion. Also succeeds if the lock 334 * is unlocked and has no writer waiters or spinners. Failing otherwise 335 * prioritizes writers before readers. 336 */ --- 256 unchanged lines hidden (view full) --- 593 if (SCHEDULER_STOPPED()) 594 return; 595 596 rw = rwlock2rw(c); 597 598 KASSERT(rw->rw_lock != RW_DESTROYED, 599 ("rw_runlock() of destroyed rwlock @ %s:%d", file, line)); 600 __rw_assert(c, RA_RLOCKED, file, line); | 329} 330/* 331 * Determines whether a new reader can acquire a lock. Succeeds if the 332 * reader already owns a read lock and the lock is locked for read to 333 * prevent deadlock from reader recursion. Also succeeds if the lock 334 * is unlocked and has no writer waiters or spinners. Failing otherwise 335 * prioritizes writers before readers. 336 */ --- 256 unchanged lines hidden (view full) --- 593 if (SCHEDULER_STOPPED()) 594 return; 595 596 rw = rwlock2rw(c); 597 598 KASSERT(rw->rw_lock != RW_DESTROYED, 599 ("rw_runlock() of destroyed rwlock @ %s:%d", file, line)); 600 __rw_assert(c, RA_RLOCKED, file, line); |
601 curthread->td_locks--; 602 curthread->td_rw_rlocks--; | |
603 WITNESS_UNLOCK(&rw->lock_object, 0, file, line); 604 LOCK_LOG_LOCK("RUNLOCK", &rw->lock_object, 0, 0, file, line); 605 606 /* TODO: drop "owner of record" here. */ 607 608 for (;;) { 609 /* 610 * See if there is more than one read lock held. If so, --- 77 unchanged lines hidden (view full) --- 688 ts = turnstile_lookup(&rw->lock_object); 689 MPASS(ts != NULL); 690 turnstile_broadcast(ts, queue); 691 turnstile_unpend(ts, TS_SHARED_LOCK); 692 turnstile_chain_unlock(&rw->lock_object); 693 break; 694 } 695 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_RUNLOCK_RELEASE, rw); | 601 WITNESS_UNLOCK(&rw->lock_object, 0, file, line); 602 LOCK_LOG_LOCK("RUNLOCK", &rw->lock_object, 0, 0, file, line); 603 604 /* TODO: drop "owner of record" here. */ 605 606 for (;;) { 607 /* 608 * See if there is more than one read lock held. If so, --- 77 unchanged lines hidden (view full) --- 686 ts = turnstile_lookup(&rw->lock_object); 687 MPASS(ts != NULL); 688 turnstile_broadcast(ts, queue); 689 turnstile_unpend(ts, TS_SHARED_LOCK); 690 turnstile_chain_unlock(&rw->lock_object); 691 break; 692 } 693 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_RUNLOCK_RELEASE, rw); |
694 curthread->td_locks--; 695 curthread->td_rw_rlocks--; |
|
696} 697 698/* 699 * This function is called when we are unable to obtain a write lock on the 700 * first try. This means that at least one other thread holds either a 701 * read or write lock. 702 */ 703void --- 529 unchanged lines hidden --- | 696} 697 698/* 699 * This function is called when we are unable to obtain a write lock on the 700 * first try. This means that at least one other thread holds either a 701 * read or write lock. 702 */ 703void --- 529 unchanged lines hidden --- |