1*a7f15a6cSFrançois Tigeot /* 2*a7f15a6cSFrançois Tigeot * Copyright (c) 2016 Mellanox Technologies, Ltd. 3*a7f15a6cSFrançois Tigeot * All rights reserved. 4*a7f15a6cSFrançois Tigeot * 5*a7f15a6cSFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6*a7f15a6cSFrançois Tigeot * modification, are permitted provided that the following conditions 7*a7f15a6cSFrançois Tigeot * are met: 8*a7f15a6cSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9*a7f15a6cSFrançois Tigeot * notice unmodified, this list of conditions, and the following 10*a7f15a6cSFrançois Tigeot * disclaimer. 11*a7f15a6cSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 12*a7f15a6cSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 13*a7f15a6cSFrançois Tigeot * documentation and/or other materials provided with the distribution. 14*a7f15a6cSFrançois Tigeot * 15*a7f15a6cSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16*a7f15a6cSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*a7f15a6cSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*a7f15a6cSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19*a7f15a6cSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*a7f15a6cSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*a7f15a6cSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*a7f15a6cSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*a7f15a6cSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*a7f15a6cSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*a7f15a6cSFrançois Tigeot */ 26*a7f15a6cSFrançois Tigeot 27*a7f15a6cSFrançois Tigeot #ifndef _ASM_ATOMIC_LONG_H_ 28*a7f15a6cSFrançois Tigeot #define _ASM_ATOMIC_LONG_H_ 29*a7f15a6cSFrançois Tigeot 30*a7f15a6cSFrançois Tigeot static inline int 31*a7f15a6cSFrançois Tigeot atomic_long_add_unless(atomic64_t *v, long a, long u) 32*a7f15a6cSFrançois Tigeot { 33*a7f15a6cSFrançois Tigeot long c = atomic64_read(v); 34*a7f15a6cSFrançois Tigeot 35*a7f15a6cSFrançois Tigeot for (;;) { 36*a7f15a6cSFrançois Tigeot if (unlikely(c == u)) 37*a7f15a6cSFrançois Tigeot break; 38*a7f15a6cSFrançois Tigeot if (likely(atomic_fcmpset_long(&v->counter, &c, c + a))) 39*a7f15a6cSFrançois Tigeot break; 40*a7f15a6cSFrançois Tigeot } 41*a7f15a6cSFrançois Tigeot return (c != u); 42*a7f15a6cSFrançois Tigeot } 43*a7f15a6cSFrançois Tigeot 44*a7f15a6cSFrançois Tigeot #define atomic_long_inc_not_zero(v) atomic_long_add_unless((v), 1, 0) 45*a7f15a6cSFrançois Tigeot 46*a7f15a6cSFrançois Tigeot #endif /* _ASM_ATOMIC_LONG_H_ */ 47