[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wi08ZUguV_n88h=bP6X01-tah29RtB0t9TmXtyuEJev-Q@mail.gmail.com>
Date: Fri, 15 Sep 2023 14:50:48 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
Alexey Dobriyan <adobriyan@...il.com>,
linux-kernel@...r.kernel.org,
Linus Walleij <linus.walleij@...aro.org>,
akpm@...ux-foundation.org
Subject: Re: Buggy __free(kfree) usage pattern already in tree
On Fri, 15 Sept 2023 at 14:32, Peter Zijlstra <peterz@...radead.org> wrote:
>
>
> It also got me thinking about named_guard() for the myriad of
> conditional locks we have.
>
> named_guard(try_mutex, foo_guard)(&foo->lock);
> if (foo_guard) {
> // we got the lock, do our thing
> }
Hmm. It looks ugly to me. I really hate the "named_guard" thing. One
of the reasons I liked the guard/scoped_guard() macros was because how
it created _anonymous_ guards, and made it completely unnecessary to
make up a pointless name.
If trylock ends up being a common pattern, I think we should strive to
make it a lot easier to use.
Can we make it act like "scoped_guard()", except the lock function is
fundamentally conditional?
Call it "cond_guard()", and make the syntax otherwise be the same as
"scoped_guard()", iow, using a unique ID for the guard name.
So
cond_guard(try_mutex)(&foo->lock) {
.. this is the "we got the lock" region ..
}
would I think be a much better syntax.
Could we live with that?
Linus
Powered by blists - more mailing lists