lkml.org 
[lkml]   [2017]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 01/14] locking/atomic: import atomic_dec_not_zero()


> On 01 February 2017 at 10:25 Peter Zijlstra <peterz@infradead.org> wrote:
>
>
> 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.

Do you know about some commit doing such conversion or could you give me 2
distinct models
so I could compare ? btw atomic_inc_not_zero() is also adviced in
Documentation/RCU/rcuref.txt

Regards,
Fabian

\
 
 \ /
  Last update: 2017-02-01 20:24    [W:0.052 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site