Re: Linus rollup

Richard Henderson
2003-01-30T02:00:07Z

On Wed, Jan 29, 2003 at 06:00:54PM -0800, Andrew Morton wrote:
> * Expected reader usage:
> * do {
> * seq = fr_read_begin();
> * ...
> * } while (seq != fr_read_end());

I think perhaps

do {
seq = fr_read_begin(&lock);
...
} while (fr_read_end(&lock, seq))

would be a better interface. This would allow you to change
the implementation as well. E.g.

unsigned fr_read_begin(frlock_t *lock)
{
unsigned s;

do
{
barrier ();
s = lock->sequence;
}
while (s & 1);
rmb();

return s;
}

int fr_read_end(frlock_t *lock, unsigned s)
{
rmb();
return s == lock->sequence;
}

void fr_write_begin(frlock_t *rw)
{
rw->sequence++;
wmb();
}

void fr_write_begin(frlock_t *rw)
{
wmb();
rw->sequence++;
}

which doesn't require as much memory.

r~