mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Fabian Frederick <fabf@skynet.be>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/14] locking/atomic: import atomic_dec_not_zero()
Date: Wed, 1 Feb 2017 10:25:21 +0100	[thread overview]
Message-ID: <20170201092521.GS6515@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <457832747.1616728.1485896108161.open-xchange@webmail.nmp.proximus.be>

On Tue, Jan 31, 2017 at 09:55:08PM +0100, Fabian Frederick wrote:
> Once again it's just about readability:

I feel APIs should be about common use-cases, not about sporadic weird cases.

> "add -1 unless value is zero" looks more complex in code than "dec not zero"
> but maybe it's just a matter of taste :) It it's not the case why would there be
> more sense about having
> atomic_inc_not_zero() globally ?

inc_not_zero() has a very strong use-case, its for lockless refcount
increment. Incrementing a 0 reference count is bad because the object
will be freed and you'll have a use-after-free.

Arguably, once we move reference counting over to its own type, it would
make sense to remove it from atomic, specifically to discourage that use
case.

  reply	other threads:[~2017-02-01  9:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30 18:39 Fabian Frederick
2017-01-31  7:33 ` Ingo Molnar
2017-01-31 10:41 ` Peter Zijlstra
2017-01-31 17:41   ` Fabian Frederick
2017-01-31 19:17     ` Peter Zijlstra
2017-01-31 20:55       ` Fabian Frederick
2017-02-01  9:25         ` Peter Zijlstra [this message]
2017-02-01 19:24           ` Fabian Frederick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170201092521.GS6515@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=fabf@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome