tech-kern archive

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

Re: Modules loading modules?

On Mon, 2 Aug 2010, Quentin Garnier wrote:

+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.

According to the mutex(9) man page:


       For adaptive mutexes, return non-zero if the current LWP holds
       the mutex. ...

The rmutex_init() code ensures that we have an adaptive mutex. So what this says is

        If _we_ already own the mutex,
                increment counter
                (rv is still initialized to 1)
        if we can acquire the mutex (updating rv)
                increment the counter


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.

It would be a no-op for a recursive spin mutex.  That's why I didn't
allow them!  :)

| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at |
| Kernel Developer |                          | pgoyette at  |

Home | Main Index | Thread Index | Old Index