kern_sx.c (167365) | kern_sx.c (167368) |
---|---|
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 167365 2007-03-09 16:04:44Z jhb $"); | 37__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 167368 2007-03-09 16:27:11Z 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> 46#include <sys/lock.h> 47#include <sys/mutex.h> 48#include <sys/proc.h> 49#include <sys/sx.h> 50#include <sys/lock_profile.h> 51 52#ifdef DDB 53#include <ddb/ddb.h> 54 55static void db_show_sx(struct lock_object *lock); 56#endif | 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> 46#include <sys/lock.h> 47#include <sys/mutex.h> 48#include <sys/proc.h> 49#include <sys/sx.h> 50#include <sys/lock_profile.h> 51 52#ifdef DDB 53#include <ddb/ddb.h> 54 55static void db_show_sx(struct lock_object *lock); 56#endif |
57static void lock_sx(struct lock_object *lock, int how); 58static int unlock_sx(struct lock_object *lock); |
|
57 58struct lock_class lock_class_sx = { 59 .lc_name = "sx", 60 .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, 61#ifdef DDB 62 .lc_ddb_show = db_show_sx, 63#endif | 59 60struct lock_class lock_class_sx = { 61 .lc_name = "sx", 62 .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, 63#ifdef DDB 64 .lc_ddb_show = db_show_sx, 65#endif |
66 .lc_lock = lock_sx, 67 .lc_unlock = unlock_sx, |
|
64}; 65 66#ifndef INVARIANTS 67#define _sx_assert(sx, what, file, line) 68#endif 69 70void | 68}; 69 70#ifndef INVARIANTS 71#define _sx_assert(sx, what, file, line) 72#endif 73 74void |
75lock_sx(struct lock_object *lock, int how) 76{ 77 struct sx *sx; 78 79 sx = (struct sx *)lock; 80 if (how) 81 sx_xlock(sx); 82 else 83 sx_slock(sx); 84} 85 86int 87unlock_sx(struct lock_object *lock) 88{ 89 struct sx *sx; 90 91 sx = (struct sx *)lock; 92 sx_assert(sx, SX_LOCKED | LA_NOTRECURSED); 93 if (sx_xlocked(sx)) { 94 sx_xunlock(sx); 95 return (1); 96 } else { 97 sx_sunlock(sx); 98 return (0); 99 } 100} 101 102void |
|
71sx_sysinit(void *arg) 72{ 73 struct sx_args *sargs = arg; 74 75 sx_init(sargs->sa_sx, sargs->sa_desc); 76} 77 78void --- 264 unchanged lines hidden (view full) --- 343void 344_sx_assert(struct sx *sx, int what, const char *file, int line) 345{ 346 347 if (panicstr != NULL) 348 return; 349 switch (what) { 350 case SX_LOCKED: | 103sx_sysinit(void *arg) 104{ 105 struct sx_args *sargs = arg; 106 107 sx_init(sargs->sa_sx, sargs->sa_desc); 108} 109 110void --- 264 unchanged lines hidden (view full) --- 375void 376_sx_assert(struct sx *sx, int what, const char *file, int line) 377{ 378 379 if (panicstr != NULL) 380 return; 381 switch (what) { 382 case SX_LOCKED: |
383 case SX_LOCKED | LA_NOTRECURSED: |
|
351 case SX_SLOCKED: 352#ifdef WITNESS 353 witness_assert(&sx->sx_object, what, file, line); 354#else 355 mtx_lock(sx->sx_lock); 356 if (sx->sx_cnt <= 0 && 357 (what == SX_SLOCKED || sx->sx_xholder != curthread)) 358 panic("Lock %s not %slocked @ %s:%d\n", --- 109 unchanged lines hidden --- | 384 case SX_SLOCKED: 385#ifdef WITNESS 386 witness_assert(&sx->sx_object, what, file, line); 387#else 388 mtx_lock(sx->sx_lock); 389 if (sx->sx_cnt <= 0 && 390 (what == SX_SLOCKED || sx->sx_xholder != curthread)) 391 panic("Lock %s not %slocked @ %s:%d\n", --- 109 unchanged lines hidden --- |