Ricardo Correia wrote: > 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.
Yes, and that is exactly how it is defined in synch.h #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x)) > 4.2) In the kernel, it only checks if the rwlock is locked (!!) > > Is this correct? Yes, I believe you have this correct. -Mark
