On 05/15/2018 02:02 PM, Matthew Wilcox wrote:
> On Tue, May 15, 2018 at 07:58:05PM +0200, Peter Zijlstra wrote:
>> On Tue, May 15, 2018 at 01:38:04PM -0400, Waiman Long wrote:
>>> +/*
>>> + * Owner value to indicate the rwsem's owner is not currently known.
>>> + */
>>> +#define RWSEM_OWNER_UNKNOWN        ((struct task_struct *)-1)
>> It might be nice to comment that this works and relies on having that
>> ANON_OWNER bit set.
> I'd rather change the definition to be ((struct task_struct *)2)
> otherwise this is both reader-owned and anonymously-owned which doesn't
> make much sense.

Thinking about it a bit more. I can actually just use one special bit
(bit 0) to designate an unknown owner. So for a reader-owned lock, it is
just owner == 1 as the owners are unknown for a reader owned lock. For a
lock owned by an unknown writer, it is (owner & 1) && (owner != 1). That
will justify the use of -1L and save bit 1 for future extension.

Cheers,
Longman




Reply via email to