Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1654133
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v5 1/3] refcount: Create unchecked atomic_t implementation |
| Date | 2017-05-31 13:20 +0200 |
| Message-ID | <tN9Ps-424-9@gated-at.bofh.it> (permalink) |
| References | <tMXbz-4e6-11@gated-at.bofh.it> <tMXbz-4e6-9@gated-at.bofh.it> <tN9mq-3zx-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, May 31, 2017 at 10:45:09AM +0000, Reshetova, Elena wrote:
> > +static inline __must_check bool refcount_add_not_zero(unsigned int i,
> > +
> > refcount_t *r)
> > +{
> > + return atomic_add_return(i, &r->refs) != 0;
> > +}
>
> Maybe atomic_add_unless(&r->refs, i, 0) in order to be consistent with the below inc_not_zero implementation?
Yes, atomic_add_return() is strictly incorrect here since the add is
unconditional.
> > +static inline __must_check bool refcount_sub_and_test(unsigned int i,
> > +
> > refcount_t *r)
> > +{
> > + return atomic_sub_return(i, &r->refs) == 0;
> > +}
>
> Any reason for not using atomic_sub_and_test() here?
> > +static inline __must_check bool refcount_dec_and_test(refcount_t *r)
> > +{
> > + return atomic_dec_return(&r->refs) == 0;
> > +}
>
> Same here: atomic_dec_and_test()?
Both those are better because they return condition codes generated from
the operand itself.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v5 1/3] refcount: Create unchecked atomic_t implementation Kees Cook <keescook@chromium.org> - 2017-05-30 23:50 +0200
RE: [PATCH v5 1/3] refcount: Create unchecked atomic_t implementation "Reshetova, Elena" <elena.reshetova@intel.com> - 2017-05-31 12:50 +0200
Re: [PATCH v5 1/3] refcount: Create unchecked atomic_t implementation Peter Zijlstra <peterz@infradead.org> - 2017-05-31 13:20 +0200
Re: [PATCH v5 1/3] refcount: Create unchecked atomic_t implementation Kees Cook <keescook@chromium.org> - 2017-06-01 16:50 +0200
csiph-web