Deleted Added
full compact
kern_mutex.c (215054) kern_mutex.c (227588)
1/*-
2 * Copyright (c) 1998 Berkeley Software Design, Inc. 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, this list of conditions and the following disclaimer.

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

29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $
30 */
31
32/*
33 * Machine independent bits of mutex implementation.
34 */
35
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Berkeley Software Design, Inc. 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, this list of conditions and the following disclaimer.

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

29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $
30 */
31
32/*
33 * Machine independent bits of mutex implementation.
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 215054 2010-11-09 20:46:41Z jhb $");
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 227588 2011-11-16 21:51:17Z pjd $");
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_global.h"
42#include "opt_kdtrace.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

80 * Internal utility macros.
81 */
82#define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED)
83
84#define mtx_destroyed(m) ((m)->mtx_lock == MTX_DESTROYED)
85
86#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
87
38
39#include "opt_adaptive_mutexes.h"
40#include "opt_ddb.h"
41#include "opt_global.h"
42#include "opt_kdtrace.h"
43#include "opt_sched.h"
44
45#include <sys/param.h>

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

80 * Internal utility macros.
81 */
82#define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED)
83
84#define mtx_destroyed(m) ((m)->mtx_lock == MTX_DESTROYED)
85
86#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
87
88static void assert_mtx(struct lock_object *lock, int what);
88static void assert_mtx(const struct lock_object *lock, int what);
89#ifdef DDB
89#ifdef DDB
90static void db_show_mtx(struct lock_object *lock);
90static void db_show_mtx(const struct lock_object *lock);
91#endif
92static void lock_mtx(struct lock_object *lock, int how);
93static void lock_spin(struct lock_object *lock, int how);
94#ifdef KDTRACE_HOOKS
91#endif
92static void lock_mtx(struct lock_object *lock, int how);
93static void lock_spin(struct lock_object *lock, int how);
94#ifdef KDTRACE_HOOKS
95static int owner_mtx(struct lock_object *lock, struct thread **owner);
95static int owner_mtx(const struct lock_object *lock,
96 struct thread **owner);
96#endif
97static int unlock_mtx(struct lock_object *lock);
98static int unlock_spin(struct lock_object *lock);
99
100/*
101 * Lock classes for sleep and spin mutexes.
102 */
103struct lock_class lock_class_mtx_sleep = {

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

129
130/*
131 * System-wide mutexes
132 */
133struct mtx blocked_lock;
134struct mtx Giant;
135
136void
97#endif
98static int unlock_mtx(struct lock_object *lock);
99static int unlock_spin(struct lock_object *lock);
100
101/*
102 * Lock classes for sleep and spin mutexes.
103 */
104struct lock_class lock_class_mtx_sleep = {

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

130
131/*
132 * System-wide mutexes
133 */
134struct mtx blocked_lock;
135struct mtx Giant;
136
137void
137assert_mtx(struct lock_object *lock, int what)
138assert_mtx(const struct lock_object *lock, int what)
138{
139
139{
140
140 mtx_assert((struct mtx *)lock, what);
141 mtx_assert((const struct mtx *)lock, what);
141}
142
143void
144lock_mtx(struct lock_object *lock, int how)
145{
146
147 mtx_lock((struct mtx *)lock);
148}

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

169unlock_spin(struct lock_object *lock)
170{
171
172 panic("spin locks can only use msleep_spin");
173}
174
175#ifdef KDTRACE_HOOKS
176int
142}
143
144void
145lock_mtx(struct lock_object *lock, int how)
146{
147
148 mtx_lock((struct mtx *)lock);
149}

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

170unlock_spin(struct lock_object *lock)
171{
172
173 panic("spin locks can only use msleep_spin");
174}
175
176#ifdef KDTRACE_HOOKS
177int
177owner_mtx(struct lock_object *lock, struct thread **owner)
178owner_mtx(const struct lock_object *lock, struct thread **owner)
178{
179{
179 struct mtx *m = (struct mtx *)lock;
180 const struct mtx *m = (const struct mtx *)lock;
180
181 *owner = mtx_owner(m);
182 return (mtx_unowned(m) == 0);
183}
184#endif
185
186/*
187 * Function versions of the inlined __mtx_* macros. These are used by

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

688 * See the __mtx_unlock_spin() macro for the details.
689 */
690
691/*
692 * The backing function for the INVARIANTS-enabled mtx_assert()
693 */
694#ifdef INVARIANT_SUPPORT
695void
181
182 *owner = mtx_owner(m);
183 return (mtx_unowned(m) == 0);
184}
185#endif
186
187/*
188 * Function versions of the inlined __mtx_* macros. These are used by

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

689 * See the __mtx_unlock_spin() macro for the details.
690 */
691
692/*
693 * The backing function for the INVARIANTS-enabled mtx_assert()
694 */
695#ifdef INVARIANT_SUPPORT
696void
696_mtx_assert(struct mtx *m, int what, const char *file, int line)
697_mtx_assert(const struct mtx *m, int what, const char *file, int line)
697{
698
699 if (panicstr != NULL || dumping)
700 return;
701 switch (what) {
702 case MA_OWNED:
703 case MA_OWNED | MA_RECURSED:
704 case MA_OWNED | MA_NOTRECURSED:

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

866 mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
867 mtx_init(&proc0.p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE);
868 mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
869 mtx_lock(&Giant);
870}
871
872#ifdef DDB
873void
698{
699
700 if (panicstr != NULL || dumping)
701 return;
702 switch (what) {
703 case MA_OWNED:
704 case MA_OWNED | MA_RECURSED:
705 case MA_OWNED | MA_NOTRECURSED:

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

867 mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
868 mtx_init(&proc0.p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE);
869 mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
870 mtx_lock(&Giant);
871}
872
873#ifdef DDB
874void
874db_show_mtx(struct lock_object *lock)
875db_show_mtx(const struct lock_object *lock)
875{
876 struct thread *td;
876{
877 struct thread *td;
877 struct mtx *m;
878 const struct mtx *m;
878
879
879 m = (struct mtx *)lock;
880 m = (const struct mtx *)lock;
880
881 db_printf(" flags: {");
882 if (LOCK_CLASS(lock) == &lock_class_mtx_spin)
883 db_printf("SPIN");
884 else
885 db_printf("DEF");
886 if (m->lock_object.lo_flags & LO_RECURSABLE)
887 db_printf(", RECURSE");

--- 25 unchanged lines hidden ---
881
882 db_printf(" flags: {");
883 if (LOCK_CLASS(lock) == &lock_class_mtx_spin)
884 db_printf("SPIN");
885 else
886 db_printf("DEF");
887 if (m->lock_object.lo_flags & LO_RECURSABLE)
888 db_printf(", RECURSE");

--- 25 unchanged lines hidden ---