Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Aug 2018 11:33:05 +0200
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Hans Petter Selasky <hselasky@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r337374 - head/sys/compat/linuxkpi/common/include/asm
Message-ID:  <CAGudoHFNL=uyN6jnbjGNCJDX1z%2BW7bt17wg2RKg=u_R759veSg@mail.gmail.com>
In-Reply-To: <201808060840.w768e2gl023307@repo.freebsd.org>
References:  <201808060840.w768e2gl023307@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Aug 6, 2018 at 10:40 AM Hans Petter Selasky <hselasky@freebsd.org>
wrote:

> Author: hselasky
> Date: Mon Aug  6 08:40:02 2018
> New Revision: 337374
> URL: https://svnweb.freebsd.org/changeset/base/337374
>
> Log:
>   Implement atomic_long_cmpxchg() function in the LinuxKPI.
>
>   Submitted by: Johannes Lundberg <johalun0@gmail.com>
>   MFC after:    1 week
>   Sponsored by: Mellanox Technologies
>
> Modified:
>   head/sys/compat/linuxkpi/common/include/asm/atomic-long.h
>
> Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h
>
> ==============================================================================
> --- head/sys/compat/linuxkpi/common/include/asm/atomic-long.h   Mon Aug  6
> 08:35:16 2018        (r337373)
> +++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h   Mon Aug  6
> 08:40:02 2018        (r337374)
> @@ -81,6 +81,21 @@ atomic_long_xchg(atomic_long_t *v, long val)
>         return atomic_swap_long(&v->counter, val);
>  }
>
> +static inline long
> +atomic_long_cmpxchg(atomic_long_t *v, long old, long new)
> +{
> +       long ret = old;
> +
> +       for (;;) {
> +               if (atomic_cmpset_long(&v->counter, old, new))
> +                       break;
> +               ret = READ_ONCE(v->counter);
> +               if (ret != old)
> +                       break;
> +       }
> +       return (ret);
> +}


This code is seriously inferior to atomic_fcmpset_long, which happens to
return the found value just like the linux atomic_long_cmpxchg would.

The atomic_cmpset_* primitives should not be used if the target value is to
be inspected.

+
>  static inline int
>  atomic_long_add_unless(atomic_long_t *v, long a, long u)
>  {
>
>

-- 
Mateusz Guzik <mjguzik gmail.com>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHFNL=uyN6jnbjGNCJDX1z%2BW7bt17wg2RKg=u_R759veSg>