Skip to content

Commit

Permalink
add separate lock class function for recursed mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmacy committed Apr 27, 2010
1 parent d307d85 commit 10290bd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions sys/kern/kern_mutex.c
Expand Up @@ -97,6 +97,7 @@ static void lock_spin(struct lock_object *lock, int how);
static int owner_mtx(struct lock_object *lock, struct thread **owner);
#endif
static int unlock_mtx(struct lock_object *lock);
static int unlock_recursable_mtx(struct lock_object *lock);
static int unlock_spin(struct lock_object *lock);

/*
Expand All @@ -111,6 +112,7 @@ struct lock_class lock_class_mtx_sleep = {
#endif
.lc_lock = lock_mtx,
.lc_unlock = unlock_mtx,
.lc_unlock_recursable = unlock_recursable_mtx,
#ifdef KDTRACE_HOOKS
.lc_owner = owner_mtx,
#endif
Expand Down Expand Up @@ -184,6 +186,17 @@ unlock_mtx(struct lock_object *lock)
{
struct mtx *m;

m = (struct mtx *)lock;
mtx_assert(m, MA_NOTRECURSED|MA_OWNED);
mtx_unlock(m);
return (0);
}

int
unlock_recursable_mtx(struct lock_object *lock)
{
struct mtx *m;

m = (struct mtx *)lock;
mtx_assert(m, MA_OWNED);
mtx_unlock(m);
Expand Down
4 changes: 2 additions & 2 deletions sys/kern/subr_lock.c
Expand Up @@ -714,7 +714,7 @@ ls_pop(struct lock_stack *ls)
ls->ls_top--;
lock = ls->ls_array[ls->ls_top].lse_lock;
class = ls->ls_array[ls->ls_top].lse_class;
class->lc_unlock(lock);
class->lc_unlock_recursable(lock);
}

void
Expand All @@ -729,7 +729,7 @@ ls_popa(struct lock_stack *ls)
ls->ls_top--;
lock = ls->ls_array[ls->ls_top].lse_lock;
class = ls->ls_array[ls->ls_top].lse_class;
class->lc_unlock(lock);
class->lc_unlock_recursable(lock);
}
}

1 change: 1 addition & 0 deletions sys/sys/lock.h
Expand Up @@ -65,6 +65,7 @@ struct lock_class {
int (*lc_unlock)(struct lock_object *lock);
void (*lc_lock_full)(struct lock_object *lock, char *file, int line);
int (*lc_trylock)(struct lock_object *lock);
int (*lc_unlock_recursable)(struct lock_object *lock);
};

#define LC_SLEEPLOCK 0x00000001 /* Sleep lock. */
Expand Down

0 comments on commit 10290bd

Please sign in to comment.