lkml.org 
[lkml]   [2021]   [Jul]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Documentation/atomic_t: Document cmpxchg() vs try_cmpxchg()
On Mon, Jul 05, 2021 at 11:25:29PM +0800, Xu, Yanfei wrote:
> > +CMPXHG vs TRY_CMPXCHG
>
> CMPXHG -> CMPXCHG

Yeah, already fixed. I spotted it a minute after sending :/

> > +---------------------
> > +
> > + int atomic_cmpxchg(atomic_t *ptr, int old, int new);
> > + bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new);
> > +
> > +Both provide the same functionality, but try_cmpxchg() can lead to more
> > +compact code. The functions relate like:
> > +
> > + bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new)
> > + {
> > + int ret, old = *oldp;
> > + ret = atomic_cmpxchg(ptr, old, new);
> > + if (ret != old)
> > + *oldp = ret;
> > + return ret == old;
> > + }
>
> I tried to search some comments about atomic_try_cmpxchg(), but failed.
> Maybe I missed it. With your this document, it is more clear now.

OK, good, thanks!

> > +
> > +and:
> > +
> > + int atomic_cmpxchg(atomic_t *ptr, int old, int new)
> > + {
> > + (void)atomic_try_cmpxchg(ptr, &old, new);
> > + return old;
> > + }
> > +
> > +Usage:
> > +
> > + old = atomic_read(&v); old = atomic_read(&v);
> > + for (;;) { do {
> > + new = func(old); new = func(old);
> > + tmp = atomic_cmpxchg(&v, old, new); } while (!atomic_try_cmpxchg(&v, &old, new));
>
> Some unnecessary spaces before "while".

That's due to the diff prepending the line with "+ " which offsets the
tabstop. If you apply the patch the actual document is fine.

\
 
 \ /
  Last update: 2021-07-05 19:13    [W:0.076 / U:0.580 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site