kern_rwlock.c (227309) | kern_rwlock.c (227588) |
---|---|
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 227309 2011-11-07 15:43:11Z ed $"); | 35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 227588 2011-11-16 21:51:17Z pjd $"); |
36 37#include "opt_ddb.h" 38#include "opt_kdtrace.h" 39#include "opt_no_adaptive_rwlocks.h" 40 41#include <sys/param.h> 42#include <sys/ktr.h> 43#include <sys/kernel.h> --- 18 unchanged lines hidden (view full) --- 62 "rwlock debugging"); 63SYSCTL_INT(_debug_rwlock, OID_AUTO, retry, CTLFLAG_RW, &rowner_retries, 0, ""); 64SYSCTL_INT(_debug_rwlock, OID_AUTO, loops, CTLFLAG_RW, &rowner_loops, 0, ""); 65#endif 66 67#ifdef DDB 68#include <ddb/ddb.h> 69 | 36 37#include "opt_ddb.h" 38#include "opt_kdtrace.h" 39#include "opt_no_adaptive_rwlocks.h" 40 41#include <sys/param.h> 42#include <sys/ktr.h> 43#include <sys/kernel.h> --- 18 unchanged lines hidden (view full) --- 62 "rwlock debugging"); 63SYSCTL_INT(_debug_rwlock, OID_AUTO, retry, CTLFLAG_RW, &rowner_retries, 0, ""); 64SYSCTL_INT(_debug_rwlock, OID_AUTO, loops, CTLFLAG_RW, &rowner_loops, 0, ""); 65#endif 66 67#ifdef DDB 68#include <ddb/ddb.h> 69 |
70static void db_show_rwlock(struct lock_object *lock); | 70static void db_show_rwlock(const struct lock_object *lock); |
71#endif | 71#endif |
72static void assert_rw(struct lock_object *lock, int what); | 72static void assert_rw(const struct lock_object *lock, int what); |
73static void lock_rw(struct lock_object *lock, int how); 74#ifdef KDTRACE_HOOKS | 73static void lock_rw(struct lock_object *lock, int how); 74#ifdef KDTRACE_HOOKS |
75static int owner_rw(struct lock_object *lock, struct thread **owner); | 75static int owner_rw(const struct lock_object *lock, struct thread **owner); |
76#endif 77static int unlock_rw(struct lock_object *lock); 78 79struct lock_class lock_class_rw = { 80 .lc_name = "rw", 81 .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, 82 .lc_assert = assert_rw, 83#ifdef DDB --- 32 unchanged lines hidden (view full) --- 116 */ 117#define rw_owner(rw) rw_wowner(rw) 118 119#ifndef INVARIANTS 120#define _rw_assert(rw, what, file, line) 121#endif 122 123void | 76#endif 77static int unlock_rw(struct lock_object *lock); 78 79struct lock_class lock_class_rw = { 80 .lc_name = "rw", 81 .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, 82 .lc_assert = assert_rw, 83#ifdef DDB --- 32 unchanged lines hidden (view full) --- 116 */ 117#define rw_owner(rw) rw_wowner(rw) 118 119#ifndef INVARIANTS 120#define _rw_assert(rw, what, file, line) 121#endif 122 123void |
124assert_rw(struct lock_object *lock, int what) | 124assert_rw(const struct lock_object *lock, int what) |
125{ 126 | 125{ 126 |
127 rw_assert((struct rwlock *)lock, what); | 127 rw_assert((const struct rwlock *)lock, what); |
128} 129 130void 131lock_rw(struct lock_object *lock, int how) 132{ 133 struct rwlock *rw; 134 135 rw = (struct rwlock *)lock; --- 16 unchanged lines hidden (view full) --- 152 } else { 153 rw_wunlock(rw); 154 return (1); 155 } 156} 157 158#ifdef KDTRACE_HOOKS 159int | 128} 129 130void 131lock_rw(struct lock_object *lock, int how) 132{ 133 struct rwlock *rw; 134 135 rw = (struct rwlock *)lock; --- 16 unchanged lines hidden (view full) --- 152 } else { 153 rw_wunlock(rw); 154 return (1); 155 } 156} 157 158#ifdef KDTRACE_HOOKS 159int |
160owner_rw(struct lock_object *lock, struct thread **owner) | 160owner_rw(const struct lock_object *lock, struct thread **owner) |
161{ | 161{ |
162 struct rwlock *rw = (struct rwlock *)lock; | 162 const struct rwlock *rw = (const struct rwlock *)lock; |
163 uintptr_t x = rw->rw_lock; 164 165 *owner = rw_wowner(rw); 166 return ((x & RW_LOCK_READ) != 0 ? (RW_READERS(x) != 0) : 167 (*owner != NULL)); 168} 169#endif 170 --- 47 unchanged lines hidden (view full) --- 218rw_sysinit_flags(void *arg) 219{ 220 struct rw_args_flags *args = arg; 221 222 rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags); 223} 224 225int | 163 uintptr_t x = rw->rw_lock; 164 165 *owner = rw_wowner(rw); 166 return ((x & RW_LOCK_READ) != 0 ? (RW_READERS(x) != 0) : 167 (*owner != NULL)); 168} 169#endif 170 --- 47 unchanged lines hidden (view full) --- 218rw_sysinit_flags(void *arg) 219{ 220 struct rw_args_flags *args = arg; 221 222 rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags); 223} 224 225int |
226rw_wowned(struct rwlock *rw) | 226rw_wowned(const struct rwlock *rw) |
227{ 228 229 return (rw_wowner(rw) == curthread); 230} 231 232void 233_rw_wlock(struct rwlock *rw, const char *file, int line) 234{ --- 771 unchanged lines hidden (view full) --- 1006#endif 1007 1008/* 1009 * In the non-WITNESS case, rw_assert() can only detect that at least 1010 * *some* thread owns an rlock, but it cannot guarantee that *this* 1011 * thread owns an rlock. 1012 */ 1013void | 227{ 228 229 return (rw_wowner(rw) == curthread); 230} 231 232void 233_rw_wlock(struct rwlock *rw, const char *file, int line) 234{ --- 771 unchanged lines hidden (view full) --- 1006#endif 1007 1008/* 1009 * In the non-WITNESS case, rw_assert() can only detect that at least 1010 * *some* thread owns an rlock, but it cannot guarantee that *this* 1011 * thread owns an rlock. 1012 */ 1013void |
1014_rw_assert(struct rwlock *rw, int what, const char *file, int line) | 1014_rw_assert(const struct rwlock *rw, int what, const char *file, int line) |
1015{ 1016 1017 if (panicstr != NULL) 1018 return; 1019 switch (what) { 1020 case RA_LOCKED: 1021 case RA_LOCKED | RA_RECURSED: 1022 case RA_LOCKED | RA_NOTRECURSED: --- 56 unchanged lines hidden (view full) --- 1079 panic("Unknown rw lock assertion: %d @ %s:%d", what, file, 1080 line); 1081 } 1082} 1083#endif /* INVARIANT_SUPPORT */ 1084 1085#ifdef DDB 1086void | 1015{ 1016 1017 if (panicstr != NULL) 1018 return; 1019 switch (what) { 1020 case RA_LOCKED: 1021 case RA_LOCKED | RA_RECURSED: 1022 case RA_LOCKED | RA_NOTRECURSED: --- 56 unchanged lines hidden (view full) --- 1079 panic("Unknown rw lock assertion: %d @ %s:%d", what, file, 1080 line); 1081 } 1082} 1083#endif /* INVARIANT_SUPPORT */ 1084 1085#ifdef DDB 1086void |
1087db_show_rwlock(struct lock_object *lock) | 1087db_show_rwlock(const struct lock_object *lock) |
1088{ | 1088{ |
1089 struct rwlock *rw; | 1089 const struct rwlock *rw; |
1090 struct thread *td; 1091 | 1090 struct thread *td; 1091 |
1092 rw = (struct rwlock *)lock; | 1092 rw = (const struct rwlock *)lock; |
1093 1094 db_printf(" state: "); 1095 if (rw->rw_lock == RW_UNLOCKED) 1096 db_printf("UNLOCKED\n"); 1097 else if (rw->rw_lock == RW_DESTROYED) { 1098 db_printf("DESTROYED\n"); 1099 return; 1100 } else if (rw->rw_lock & RW_LOCK_READ) --- 27 unchanged lines hidden --- | 1093 1094 db_printf(" state: "); 1095 if (rw->rw_lock == RW_UNLOCKED) 1096 db_printf("UNLOCKED\n"); 1097 else if (rw->rw_lock == RW_DESTROYED) { 1098 db_printf("DESTROYED\n"); 1099 return; 1100 } else if (rw->rw_lock & RW_LOCK_READ) --- 27 unchanged lines hidden --- |