Re: [PATCH v2 1/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave()

From: Peter Zijlstra
Date: Wed Oct 08 2025 - 08:56:53 EST


On Wed, Oct 08, 2025 at 02:30:45PM +0200, Oleg Nesterov wrote:
> The read_seqbegin/need_seqretry/done_seqretry API is cumbersome and
> error prone. With the new helper the "typical" code like
>
> int seq, nextseq;
> unsigned long flags;
>
> nextseq = 0;
> do {
> seq = nextseq;
> flags = read_seqbegin_or_lock_irqsave(&seqlock, &seq);
>
> // read-side critical section
>
> nextseq = 1;
> } while (need_seqretry(&seqlock, seq));
> done_seqretry_irqrestore(&seqlock, seq, flags);
>
> can be rewritten as
>
> scoped_seqlock_read_irqsave (&seqlock) {
> // read-side critical section
> }
>

Hmm, on first reading I was expecting that to be:

do {
seq = read_seqbegin(&seqlock);

// read-side section

} while (read_seqretry(&seqlock, seq));

for lack of that _or_lock() wording, but I suppose we can make that
something like:

scoped_seqbegin_read (&seqlock) {
// read-side section
}

which is distinctive enough.