tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Modules loading modules?



On Sun, Aug 01, 2010 at 05:17:01PM -0700, Paul Goyette wrote:
[...]
> +void
> +rmutex_enter(rmutex_t *rmtx)
> +{
> +     if (mutex_owned(&rmtx->rmtx_mtx)) {
> +             rmtx->rmtx_recurse++;
> +             KASSERT(rmtx->rmtx_recurse != 0);
> +     } else {
> +             mutex_enter(&rmtx->rmtx_mtx);
> +             rmtx->rmtx_recurse = 1;
> +     }
> +}
> +
> +void
> +rmutex_exit(rmutex_t *rmtx)
> +{
> +     KASSERT(mutex_owned(&rmtx->rmtx_mtx));
> +     KASSERT(rmtx->rmtx_recurse != 0);
> +     if (--rmtx->rmtx_recurse == 0)
> +             mutex_exit(&rmtx->rmtx_mtx);
> +}
> +
> +int
> +rmutex_tryenter(rmutex_t *rmtx)
> +{
> +     int rv = 1;
> +
> +     if (mutex_owned(&rmtx->rmtx_mtx)) {
> +             rmtx->rmtx_recurse++;
> +             KASSERT(rmtx->rmtx_recurse != 0);
> +     } else if ((rv = mutex_tryenter(&rmtx->rmtx_mtx)) != 0) {
> +             rmtx->rmtx_recurse++;
> +             KASSERT(rmtx->rmtx_recurse != 0);
> +     }
> +     return rv;
> +}

I am probably not getting the idea, but I fail to see how this qualifies
as a mutex.  My reading of this piece of code is that rmutex_enter() is
always going to succeed immediately.

Please correct me if I'm wrong--and I am very probably wrong--, but
isn't the point of a recursive mutex to allow the thread initially
taking the mutex to take it again, but not other threads?  The code
would have to be a lot more complicated than that.

All I see here is a fancy no-op, but maybe it's just me.

-- 
Quentin Garnier - cube%cubidou.net@localhost - cube%NetBSD.org@localhost
"See the look on my face from staying too long in one place
[...] every time the morning breaks I know I'm closer to falling"
KT Tunstall, Saving My Face, Drastic Fantastic, 2007.

Attachment: pgptUpB6P8Ib4.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index