Ok, I took a look at the libc and the kernel implementation of rwlocks.

I'm a little worried if I got this right, because most of the ZFS code can run 
both in userspace and in the kernel, which seem to behave differently in the 
RW_xxx_HELD() macros, and I need to port it correctly.

This is what I understood, please correct me if I got something wrong:

1) Like you said, libc keeps track of which reader locks are held by a given 
thread
2) The kernel only keeps track of either:
        2.1) The thread that has the rwlock locked for writing
        2.2) Or the number of readers that have the rwlock locked for reading

3) The RW_READ_HELD() macro:
    3.1) In userspace, checks if the current thread holds the rwlock locked 
for reading
    3.2) In the kernel, only checks if the rwlock is locked for reading (by 
any thread)

4) The RW_LOCK_HELD() macro:
    4.1) In userspace, is equivalent to RW_READ_HELD() || RW_WRITE_HELD(), so 
basically it checks if the current thread has the rwlock locked.
    4.2) In the kernel, it only checks if the rwlock is locked (!!)

Is this correct?

Thank you for helping.

On another note, I already got zdb to compile in Linux. Cool, heh? ;)

On Tuesday 06 June 2006 19:17, Jonathan Adams wrote:
> Our userland threads library keeps track, of which reader locks are held by
> a given thread.  If you look at the implementation of _rw_read_held():
>
> http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/port/threads/rwl
>ock.c#_rw_read_held
>
> it checks the current thread's list of locks to verify that it is not being
> held.

Reply via email to