mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-13 10:02:38 +00:00
Change mtx_init() to now take an extra argument. The third argument is
the generic lock type for use with witness. If this argument is NULL then the lock name is used as the lock type. Add a macro for a lock type name for network driver locks.
This commit is contained in:
parent
9939f0f11c
commit
0c88508a78
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=93813
@ -789,15 +789,17 @@ mtx_sysinit(void *arg)
|
||||
{
|
||||
struct mtx_args *margs = arg;
|
||||
|
||||
mtx_init(margs->ma_mtx, margs->ma_desc, margs->ma_opts);
|
||||
mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mutex initialization routine; initialize lock `m' of type contained in
|
||||
* `opts' with options contained in `opts' and description `description.'
|
||||
* `opts' with options contained in `opts' and name `name.' The optional
|
||||
* lock type `type' is used as a general lock category name for use with
|
||||
* witness.
|
||||
*/
|
||||
void
|
||||
mtx_init(struct mtx *m, const char *description, int opts)
|
||||
mtx_init(struct mtx *m, const char *name, const char *type, int opts)
|
||||
{
|
||||
struct lock_object *lock;
|
||||
|
||||
@ -811,13 +813,14 @@ mtx_init(struct mtx *m, const char *description, int opts)
|
||||
|
||||
lock = &m->mtx_object;
|
||||
KASSERT((lock->lo_flags & LO_INITIALIZED) == 0,
|
||||
("mutex %s %p already initialized", description, m));
|
||||
("mutex %s %p already initialized", name, m));
|
||||
bzero(m, sizeof(*m));
|
||||
if (opts & MTX_SPIN)
|
||||
lock->lo_class = &lock_class_mtx_spin;
|
||||
else
|
||||
lock->lo_class = &lock_class_mtx_sleep;
|
||||
lock->lo_name = description;
|
||||
lock->lo_name = name;
|
||||
lock->lo_type = type != NULL ? type : name;
|
||||
if (opts & MTX_QUIET)
|
||||
lock->lo_flags = LO_QUIET;
|
||||
if (opts & MTX_RECURSE)
|
||||
@ -877,9 +880,9 @@ mutex_init(void)
|
||||
/*
|
||||
* Initialize mutexes.
|
||||
*/
|
||||
mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
|
||||
mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
|
||||
mtx_init(&proc0.p_mtx, "process lock", MTX_DEF | MTX_DUPOK);
|
||||
mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
|
||||
mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE);
|
||||
mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
|
||||
mtx_lock(&Giant);
|
||||
}
|
||||
|
||||
|
@ -789,15 +789,17 @@ mtx_sysinit(void *arg)
|
||||
{
|
||||
struct mtx_args *margs = arg;
|
||||
|
||||
mtx_init(margs->ma_mtx, margs->ma_desc, margs->ma_opts);
|
||||
mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mutex initialization routine; initialize lock `m' of type contained in
|
||||
* `opts' with options contained in `opts' and description `description.'
|
||||
* `opts' with options contained in `opts' and name `name.' The optional
|
||||
* lock type `type' is used as a general lock category name for use with
|
||||
* witness.
|
||||
*/
|
||||
void
|
||||
mtx_init(struct mtx *m, const char *description, int opts)
|
||||
mtx_init(struct mtx *m, const char *name, const char *type, int opts)
|
||||
{
|
||||
struct lock_object *lock;
|
||||
|
||||
@ -811,13 +813,14 @@ mtx_init(struct mtx *m, const char *description, int opts)
|
||||
|
||||
lock = &m->mtx_object;
|
||||
KASSERT((lock->lo_flags & LO_INITIALIZED) == 0,
|
||||
("mutex %s %p already initialized", description, m));
|
||||
("mutex %s %p already initialized", name, m));
|
||||
bzero(m, sizeof(*m));
|
||||
if (opts & MTX_SPIN)
|
||||
lock->lo_class = &lock_class_mtx_spin;
|
||||
else
|
||||
lock->lo_class = &lock_class_mtx_sleep;
|
||||
lock->lo_name = description;
|
||||
lock->lo_name = name;
|
||||
lock->lo_type = type != NULL ? type : name;
|
||||
if (opts & MTX_QUIET)
|
||||
lock->lo_flags = LO_QUIET;
|
||||
if (opts & MTX_RECURSE)
|
||||
@ -877,9 +880,9 @@ mutex_init(void)
|
||||
/*
|
||||
* Initialize mutexes.
|
||||
*/
|
||||
mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
|
||||
mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
|
||||
mtx_init(&proc0.p_mtx, "process lock", MTX_DEF | MTX_DUPOK);
|
||||
mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
|
||||
mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE);
|
||||
mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
|
||||
mtx_lock(&Giant);
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@
|
||||
* [See below for descriptions]
|
||||
*
|
||||
*/
|
||||
void mtx_init(struct mtx *m, const char *description, int opts);
|
||||
void mtx_init(struct mtx *m, const char *name, const char *type, int opts);
|
||||
void mtx_destroy(struct mtx *m);
|
||||
void mtx_sysinit(void *arg);
|
||||
void mutex_init(void);
|
||||
@ -370,6 +370,11 @@ struct mtx_args {
|
||||
#define GIANT_REQUIRED
|
||||
#endif /* INVARIANTS */
|
||||
|
||||
/*
|
||||
* Common lock type names.
|
||||
*/
|
||||
#define MTX_NETWORK_LOCK "network driver"
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* !LOCORE */
|
||||
#endif /* _SYS_MUTEX_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user