msleep() on recursivly locked mutexes
Hans Petter Selasky
hselasky at c2i.net
Thu Apr 26 20:37:04 UTC 2007
Hi,
In the new USB stack I have defined the following:
u_int32_t
mtx_drop_recurse(struct mtx *mtx)
{
u_int32_t recurse_level = mtx->mtx_recurse;
u_int32_t recurse_curr = recurse_level;
mtx_assert(mtx, MA_OWNED);
while(recurse_curr--) {
mtx_unlock(mtx);
}
return recurse_level;
}
void
mtx_pickup_recurse(struct mtx *mtx, u_int32_t recurse_level)
{
mtx_assert(mtx, MA_OWNED);
while(recurse_level--) {
mtx_lock(mtx);
}
return;
}
When I do a msleep() I do it like this:
level = mtx_drop_recurse(ctd->p_mtx);
error = msleep(ctd, ctd->p_mtx, 0,
"config td sleep", timeout);
mtx_pickup_recurse(ctd->p_mtx, level);
Are there any comments on integrating this functionality into msleep(), and
adding mtx_drop_recurse() and mtx_pickup_recurse() to the FreeBSD kernel?
--HPS
More information about the freebsd-hackers
mailing list