Re: svn commit: r334712 - head/sys/compat/linuxkpi/common/include/asm
On 06/06/18 17:06, Mateusz Guzik wrote: On Wed, Jun 6, 2018 at 3:59 PM, Hans Petter Selasky wrote: cmpset loops are crap since they require an explicit re-read of the target value see fcmpset and refcount_acquire_if_not_zero for an example use See r334718. Thank you! --HPS ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r334712 - head/sys/compat/linuxkpi/common/include/asm
On Wed, Jun 6, 2018 at 3:59 PM, Hans Petter Selasky wrote: > Author: hselasky > Date: Wed Jun 6 13:59:51 2018 > New Revision: 334712 > URL: https://svnweb.freebsd.org/changeset/base/334712 > > Log: > Implement the atomic_dec_if_positive() function in the LinuxKPI. > > Submitted by: Johannes Lundberg > MFC after:1 week > Sponsored by: Mellanox Technologies > Sponsored by: Limelight Networks > > Modified: > head/sys/compat/linuxkpi/common/include/asm/atomic.h > > Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h > > == > --- head/sys/compat/linuxkpi/common/include/asm/atomic.hWed Jun > 6 13:37:31 2018(r334711) > +++ head/sys/compat/linuxkpi/common/include/asm/atomic.hWed Jun > 6 13:59:51 2018(r334712) > @@ -235,6 +235,22 @@ atomic_cmpxchg(atomic_t *v, int old, int new) > __ret.val; \ > }) > > +static inline int > +atomic_dec_if_positive(atomic_t *v) > +{ > + int retval; > + int curr; > + > + do { > + curr = atomic_read(v); > + retval = curr - 1; > + if (unlikely(retval < 0)) > + break; > + } while (!likely(atomic_cmpset_int(>counter, curr, retval))); > + > + return (retval); > +} > + > cmpset loops are crap since they require an explicit re-read of the target value see fcmpset and refcount_acquire_if_not_zero for an example use -- Mateusz Guzik ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
svn commit: r334712 - head/sys/compat/linuxkpi/common/include/asm
Author: hselasky Date: Wed Jun 6 13:59:51 2018 New Revision: 334712 URL: https://svnweb.freebsd.org/changeset/base/334712 Log: Implement the atomic_dec_if_positive() function in the LinuxKPI. Submitted by: Johannes Lundberg MFC after:1 week Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h == --- head/sys/compat/linuxkpi/common/include/asm/atomic.hWed Jun 6 13:37:31 2018(r334711) +++ head/sys/compat/linuxkpi/common/include/asm/atomic.hWed Jun 6 13:59:51 2018(r334712) @@ -235,6 +235,22 @@ atomic_cmpxchg(atomic_t *v, int old, int new) __ret.val; \ }) +static inline int +atomic_dec_if_positive(atomic_t *v) +{ + int retval; + int curr; + + do { + curr = atomic_read(v); + retval = curr - 1; + if (unlikely(retval < 0)) + break; + } while (!likely(atomic_cmpset_int(>counter, curr, retval))); + + return (retval); +} + #defineLINUX_ATOMIC_OP(op, c_op) \ static inline void atomic_##op(int i, atomic_t *v) \ { \ ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"