[RFC][PATCH 0/2] Lock and Pointer guards

Peter Zijlstra posted 2 patches 2 years, 8 months ago
There is a newer version of this series
[RFC][PATCH 0/2] Lock and Pointer guards
Posted by Peter Zijlstra 2 years, 8 months ago
Hi!

Yesterday I was annoyed for the lack of RAII lock guards for entirely spurious
reason, but since you sometimes gotta do silly things I spend today creating some.

My initial (failed) attempts tried to combine __cleanup, _Generic and
__auto_type, but the compilers refused. I've also Googled around and found
(among many others) the QEMU and Glib guards. However I don't like them because
they end up relying on function pointers/indirect calls.

Hence the current pile of CPP hackery.. no indirect calls in sight.

I really like how they end up simplifying the code, but perhaps y'all hate them
with a passion?

I'm thinking we'll at least have a good brawl over naming, esp. the void_guard
needs a better name.

Compile and boot tested with x86_64-defconfig.
Re: [RFC][PATCH 0/2] Lock and Pointer guards
Posted by Paolo Bonzini 2 years, 8 months ago
On 5/26/23 17:05, Peter Zijlstra wrote:
> My initial (failed) attempts tried to combine __cleanup, _Generic and
> __auto_type, but the compilers refused. I've also Googled around and found
> (among many others) the QEMU and Glib guards. However I don't like them because
> they end up relying on function pointers/indirect calls.
> 
> Hence the current pile of CPP hackery.. no indirect calls in sight.

QEMU's guards in practice also compiles down to direct calls, but yes 
that's only after the compiler inlines everything in the vtable.  I did 
it that way because the polymorphic locks already existed before, 
otherwise your solution with Linus's tweak for "bool" is as nice as it 
can be.  I like that it extends to irqoff and irqsave sections.

Paolo