Deleted Added
full compact
kern_rwlock.c (167365) kern_rwlock.c (167368)
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 167365 2007-03-09 16:04:44Z jhb $");
35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 167368 2007-03-09 16:27:11Z jhb $");
36
37#include "opt_ddb.h"
38
39#include <sys/param.h>
40#include <sys/ktr.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>
43#include <sys/proc.h>
44#include <sys/rwlock.h>
45#include <sys/systm.h>
46#include <sys/turnstile.h>
47#include <sys/lock_profile.h>
48#include <machine/cpu.h>
49
50#ifdef DDB
51#include <ddb/ddb.h>
52
53static void db_show_rwlock(struct lock_object *lock);
54#endif
36
37#include "opt_ddb.h"
38
39#include <sys/param.h>
40#include <sys/ktr.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>
43#include <sys/proc.h>
44#include <sys/rwlock.h>
45#include <sys/systm.h>
46#include <sys/turnstile.h>
47#include <sys/lock_profile.h>
48#include <machine/cpu.h>
49
50#ifdef DDB
51#include <ddb/ddb.h>
52
53static void db_show_rwlock(struct lock_object *lock);
54#endif
55static void lock_rw(struct lock_object *lock, int how);
56static int unlock_rw(struct lock_object *lock);
55
56struct lock_class lock_class_rw = {
57 .lc_name = "rw",
58 .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE,
59#ifdef DDB
60 .lc_ddb_show = db_show_rwlock,
61#endif
57
58struct lock_class lock_class_rw = {
59 .lc_name = "rw",
60 .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE,
61#ifdef DDB
62 .lc_ddb_show = db_show_rwlock,
63#endif
64 .lc_lock = lock_rw,
65 .lc_unlock = unlock_rw,
62};
63
64/*
65 * Return a pointer to the owning thread if the lock is write-locked or
66 * NULL if the lock is unlocked or read-locked.
67 */
68#define rw_wowner(rw) \
69 ((rw)->rw_lock & RW_LOCK_READ ? NULL : \

--- 6 unchanged lines hidden (view full) ---

76 */
77#define rw_owner(rw) rw_wowner(rw)
78
79#ifndef INVARIANTS
80#define _rw_assert(rw, what, file, line)
81#endif
82
83void
66};
67
68/*
69 * Return a pointer to the owning thread if the lock is write-locked or
70 * NULL if the lock is unlocked or read-locked.
71 */
72#define rw_wowner(rw) \
73 ((rw)->rw_lock & RW_LOCK_READ ? NULL : \

--- 6 unchanged lines hidden (view full) ---

80 */
81#define rw_owner(rw) rw_wowner(rw)
82
83#ifndef INVARIANTS
84#define _rw_assert(rw, what, file, line)
85#endif
86
87void
88lock_rw(struct lock_object *lock, int how)
89{
90 struct rwlock *rw;
91
92 rw = (struct rwlock *)lock;
93 if (how)
94 rw_wlock(rw);
95 else
96 rw_rlock(rw);
97}
98
99int
100unlock_rw(struct lock_object *lock)
101{
102 struct rwlock *rw;
103
104 rw = (struct rwlock *)lock;
105 rw_assert(rw, RA_LOCKED | LA_NOTRECURSED);
106 if (rw->rw_lock & RW_LOCK_READ) {
107 rw_runlock(rw);
108 return (0);
109 } else {
110 rw_wunlock(rw);
111 return (1);
112 }
113}
114
115void
84rw_init(struct rwlock *rw, const char *name)
85{
86
87 rw->rw_lock = RW_UNLOCKED;
88
89 lock_profile_object_init(&rw->rw_object, &lock_class_rw, name);
90 lock_init(&rw->rw_object, &lock_class_rw, name, NULL, LO_WITNESS |
91 LO_RECURSABLE | LO_UPGRADABLE);

--- 661 unchanged lines hidden (view full) ---

753void
754_rw_assert(struct rwlock *rw, int what, const char *file, int line)
755{
756
757 if (panicstr != NULL)
758 return;
759 switch (what) {
760 case RA_LOCKED:
116rw_init(struct rwlock *rw, const char *name)
117{
118
119 rw->rw_lock = RW_UNLOCKED;
120
121 lock_profile_object_init(&rw->rw_object, &lock_class_rw, name);
122 lock_init(&rw->rw_object, &lock_class_rw, name, NULL, LO_WITNESS |
123 LO_RECURSABLE | LO_UPGRADABLE);

--- 661 unchanged lines hidden (view full) ---

785void
786_rw_assert(struct rwlock *rw, int what, const char *file, int line)
787{
788
789 if (panicstr != NULL)
790 return;
791 switch (what) {
792 case RA_LOCKED:
793 case RA_LOCKED | LA_NOTRECURSED:
761 case RA_RLOCKED:
762#ifdef WITNESS
763 witness_assert(&rw->rw_object, what, file, line);
764#else
765 /*
766 * If some other thread has a write lock or we have one
767 * and are asserting a read lock, fail. Also, if no one
768 * has a lock at all, fail.

--- 72 unchanged lines hidden ---
794 case RA_RLOCKED:
795#ifdef WITNESS
796 witness_assert(&rw->rw_object, what, file, line);
797#else
798 /*
799 * If some other thread has a write lock or we have one
800 * and are asserting a read lock, fail. Also, if no one
801 * has a lock at all, fail.

--- 72 unchanged lines hidden ---