kern_sx.c (244582) | kern_sx.c (252212) |
---|---|
1/*- 2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org> 3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 28 unchanged lines hidden (view full) --- 37 */ 38 39#include "opt_ddb.h" 40#include "opt_hwpmc_hooks.h" 41#include "opt_kdtrace.h" 42#include "opt_no_adaptive_sx.h" 43 44#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org> 3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 28 unchanged lines hidden (view full) --- 37 */ 38 39#include "opt_ddb.h" 40#include "opt_hwpmc_hooks.h" 41#include "opt_kdtrace.h" 42#include "opt_no_adaptive_sx.h" 43 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 244582 2012-12-22 09:37:34Z attilio $"); | 45__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 252212 2013-06-25 20:23:08Z jhb $"); |
46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kdb.h> 50#include <sys/ktr.h> 51#include <sys/lock.h> 52#include <sys/mutex.h> 53#include <sys/proc.h> --- 169 unchanged lines hidden (view full) --- 223 if (!(opts & SX_NOWITNESS)) 224 flags |= LO_WITNESS; 225 if (opts & SX_RECURSE) 226 flags |= LO_RECURSABLE; 227 if (opts & SX_QUIET) 228 flags |= LO_QUIET; 229 230 flags |= opts & SX_NOADAPTIVE; | 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kdb.h> 50#include <sys/ktr.h> 51#include <sys/lock.h> 52#include <sys/mutex.h> 53#include <sys/proc.h> --- 169 unchanged lines hidden (view full) --- 223 if (!(opts & SX_NOWITNESS)) 224 flags |= LO_WITNESS; 225 if (opts & SX_RECURSE) 226 flags |= LO_RECURSABLE; 227 if (opts & SX_QUIET) 228 flags |= LO_QUIET; 229 230 flags |= opts & SX_NOADAPTIVE; |
231 lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags); |
|
231 sx->sx_lock = SX_LOCK_UNLOCKED; 232 sx->sx_recurse = 0; | 232 sx->sx_lock = SX_LOCK_UNLOCKED; 233 sx->sx_recurse = 0; |
233 lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags); | |
234} 235 236void 237sx_destroy(struct sx *sx) 238{ 239 240 KASSERT(sx->sx_lock == SX_LOCK_UNLOCKED, ("sx lock still held")); 241 KASSERT(sx->sx_recurse == 0, ("sx lock still recursed")); --- 115 unchanged lines hidden (view full) --- 357_sx_sunlock(struct sx *sx, const char *file, int line) 358{ 359 360 if (SCHEDULER_STOPPED()) 361 return; 362 KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, 363 ("sx_sunlock() of destroyed sx @ %s:%d", file, line)); 364 _sx_assert(sx, SA_SLOCKED, file, line); | 234} 235 236void 237sx_destroy(struct sx *sx) 238{ 239 240 KASSERT(sx->sx_lock == SX_LOCK_UNLOCKED, ("sx lock still held")); 241 KASSERT(sx->sx_recurse == 0, ("sx lock still recursed")); --- 115 unchanged lines hidden (view full) --- 357_sx_sunlock(struct sx *sx, const char *file, int line) 358{ 359 360 if (SCHEDULER_STOPPED()) 361 return; 362 KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, 363 ("sx_sunlock() of destroyed sx @ %s:%d", file, line)); 364 _sx_assert(sx, SA_SLOCKED, file, line); |
365 curthread->td_locks--; | |
366 WITNESS_UNLOCK(&sx->lock_object, 0, file, line); 367 LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line); 368 __sx_sunlock(sx, file, line); 369 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_SUNLOCK_RELEASE, sx); | 365 WITNESS_UNLOCK(&sx->lock_object, 0, file, line); 366 LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line); 367 __sx_sunlock(sx, file, line); 368 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_SUNLOCK_RELEASE, sx); |
369 curthread->td_locks--; |
|
370} 371 372void 373_sx_xunlock(struct sx *sx, const char *file, int line) 374{ 375 376 if (SCHEDULER_STOPPED()) 377 return; 378 KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, 379 ("sx_xunlock() of destroyed sx @ %s:%d", file, line)); 380 _sx_assert(sx, SA_XLOCKED, file, line); | 370} 371 372void 373_sx_xunlock(struct sx *sx, const char *file, int line) 374{ 375 376 if (SCHEDULER_STOPPED()) 377 return; 378 KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, 379 ("sx_xunlock() of destroyed sx @ %s:%d", file, line)); 380 _sx_assert(sx, SA_XLOCKED, file, line); |
381 curthread->td_locks--; | |
382 WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line); 383 LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file, 384 line); 385 if (!sx_recursed(sx)) 386 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_XUNLOCK_RELEASE, sx); 387 __sx_xunlock(sx, curthread, file, line); | 381 WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line); 382 LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file, 383 line); 384 if (!sx_recursed(sx)) 385 LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_XUNLOCK_RELEASE, sx); 386 __sx_xunlock(sx, curthread, file, line); |
387 curthread->td_locks--; |
|
388} 389 390/* 391 * Try to do a non-blocking upgrade from a shared lock to an exclusive lock. 392 * This will only succeed if this thread holds a single shared lock. 393 * Return 1 if if the upgrade succeed, 0 otherwise. 394 */ 395int --- 819 unchanged lines hidden --- | 388} 389 390/* 391 * Try to do a non-blocking upgrade from a shared lock to an exclusive lock. 392 * This will only succeed if this thread holds a single shared lock. 393 * Return 1 if if the upgrade succeed, 0 otherwise. 394 */ 395int --- 819 unchanged lines hidden --- |