locking/atomic: import atomic_dec_not_zero()
Subsystems (3)
PATCH 1/14 locking/atomic: import atomic_dec_not_zero()
complementary definition to atomic_inc_not_zero() featured in lib/fault-inject.c
--- include/linux/atomic.h | 2 ++ lib/fault-inject.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/atomic.h +2 -0
@@ -517,6 +517,8 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)#define atomic_inc_not_zero (v) atomic_add_unless((v), 1, 0)#endif +#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0) +#ifndef atomic_andnotstatic inline void atomic_andnot (int i,atomic_t *v) {
lib/fault-inject.c +0 -2
@@ -52,8 +52,6 @@ static void fail_dump(struct fault_attr *attr) } } -#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0) -static bool fail_task (struct fault_attr *attr,struct task_struct *task) {return !in_interrupt () && task->make_it_fail;
Signature · 1 line
2.9.3
Quoted 27 lines · Fabian Frederick
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.cSigned-off-by Fabian Frederick <[email protected]>--- include/linux/atomic.h | 2 ++ lib/fault-inject.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)include/linux/atomic.h +2
-0@@ -517,6 +517,8 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)#define atomic_inc_not_zero (v) atomic_add_unless((v), 1, 0)#endif +#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0) +#ifndef atomic_andnotstatic inline void atomic_andnot (int i,atomic_t *v) {lib/fault-inject.c +0
-0
lib/fault-inject.c static void fail_dump(struct fault_attr *attr) · line 56
Quoted 5 lines
lib/fault-inject.c +0
-2@@ -52,8 +52,6 @@ static void fail_dump(struct fault_attr *attr) } } -#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0) -
Why did you convert the tabs to spaces?
Thanks,
Ingo
Peter Zijlstra
maintainerQuoted 2 lines · Fabian Frederick
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.c
Why?
Quoted 10 lines · On 31 January 2017 at 11:41 Peter Zijlstra <[email protected]> wrote:
Quoted 2 lines · Fabian Frederick
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.cWhy?
Maybe this commit message should be ok ?
complementary definition to atomic_inc_not_zero() featured in lib/fault-inject.c and is more readable than atomic_add_unless((v), -1, 0) used in different places.
Andrew, do I have to submit this patch again replacing spaces with tabs in code line ?
Regards,
Fabian
Peter Zijlstra
maintainerQuoted 9 lines · Fabian Frederick
Quoted 9 lines · On 31 January 2017 at 11:41 Peter Zijlstra <[email protected]> wrote:
Quoted 2 lines · Fabian Frederick
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.c
Quoted 7 lines
Quoted 1 line
Why?
Maybe this commit message should be ok ?
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.cand is more readable thanatomic_add_unless((v), -1, 0)used in different places.
I still don't see why such a primitive makes sense. Yes there's a few usage sites, but from them I don't see a sensible pattern.
What sane pattern desires this?
Quoted 24 lines · On 31 January 2017 at 20:17 Peter Zijlstra <[email protected]> wrote:
Quoted 9 lines · Fabian Frederick
Quoted 9 lines · On 31 January 2017 at 11:41 Peter Zijlstra <[email protected]> wrote:
Quoted 2 lines · Fabian Frederick
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.cQuoted 8 lines
Quoted 1 line
Why?
Maybe this commit message should be ok ?
complementary definition to
atomic_inc_not_zero()featured inlib/fault-inject.c
and is more readable thanatomic_add_unless((v), -1, 0)used in different places.
Quoted 4 lines
I still don't see why such a primitive makes sense. Yes there's a few usage sites, but from them I don't see a sensible pattern.
What sane pattern desires this?
Once again it's just about readability:
"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 havingatomic_inc_not_zero() globally ?
Regards,
Fabian
Peter Zijlstra
maintainerQuoted 1 line · Fabian Frederick
Once again it's just about readability:
I feel APIs should be about common use-cases, not about sporadic weird cases.
Quoted 4 lines
"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.
Quoted 16 lines · On 01 February 2017 at 10:25 Peter Zijlstra <[email protected]> wrote:
Quoted 1 line · Fabian Frederick
Once again it's just about readability:
I feel APIs should be about common use-cases, not about sporadic weird cases.
Quoted 5 lines
"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 havingatomic_inc_not_zero()globally ?
Quoted 7 lines
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