Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/include/linux atomic_dec_if_positive



details:   https://anonhg.NetBSD.org/src/rev/9922cec1913d
branches:  trunk
changeset: 1028062:9922cec1913d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 01:45:53 2021 +0000

description:
atomic_dec_if_positive

diffstat:

 sys/external/bsd/drm2/include/linux/atomic.h |  19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diffs (33 lines):

diff -r 59f5ca10a771 -r 9922cec1913d sys/external/bsd/drm2/include/linux/atomic.h
--- a/sys/external/bsd/drm2/include/linux/atomic.h      Sun Dec 19 01:45:44 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/atomic.h      Sun Dec 19 01:45:53 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.h,v 1.27 2021/12/19 01:44:19 riastradh Exp $    */
+/*     $NetBSD: atomic.h,v 1.28 2021/12/19 01:45:53 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -155,6 +155,23 @@
        return atomic_dec_return(atomic) == 0;
 }
 
+static inline int
+atomic_dec_if_positive(atomic_t *atomic)
+{
+       int v;
+
+       smp_mb__before_atomic();
+       do {
+               v = atomic->a_u.au_uint;
+               __insn_barrier();
+               if (v <= 0)
+                       break;
+       } while (atomic_cas_uint(&atomic->a_u.au_uint, v, v - 1) != v);
+       smp_mb__after_atomic();
+
+       return v - 1;
+}
+
 static inline void
 atomic_or(int value, atomic_t *atomic)
 {



Home | Main Index | Thread Index | Old Index