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 Provide kref_put_lock



details:   https://anonhg.NetBSD.org/src/rev/2f8e0861beef
branches:  trunk
changeset: 1028671:2f8e0861beef
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:39:00 2021 +0000

description:
Provide kref_put_lock


Author: Maya Rashish <maya%NetBSD.org@localhost>
Committer: Taylor R Campbell <riastradh%NetBSD.org@localhost>

diffstat:

 sys/external/bsd/drm2/include/linux/kref.h |  30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r 4165415a7c9e -r 2f8e0861beef sys/external/bsd/drm2/include/linux/kref.h
--- a/sys/external/bsd/drm2/include/linux/kref.h        Sun Dec 19 11:38:53 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/kref.h        Sun Dec 19 11:39:00 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kref.h,v 1.10 2021/12/19 10:48:37 riastradh Exp $      */
+/*     $NetBSD: kref.h,v 1.11 2021/12/19 11:39:00 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -39,6 +39,7 @@
 #include <linux/atomic.h>
 #include <linux/refcount.h>
 #include <linux/mutex.h>
+#include <linux/spinlock.h>
 
 struct kref {
        unsigned int kr_count;
@@ -107,6 +108,33 @@
 }
 
 static inline int
+kref_put_lock(struct kref *kref, void (*release)(struct kref *), spinlock_t *interlock)
+{
+       unsigned int old, new;
+
+#ifndef __HAVE_ATOMIC_AS_MEMBAR
+       membar_exit();
+#endif
+
+       do {
+               old = kref->kr_count;
+               KASSERT(old > 0);
+               if (old == 1) {
+                       spin_lock(interlock);
+                       if (atomic_add_int_nv(&kref->kr_count, -1) == 0) {
+                               (*release)(kref);
+                               return 1;
+                       }
+                       spin_unlock(interlock);
+                       return 0;
+               }
+               new = (old - 1);
+       } while (atomic_cas_uint(&kref->kr_count, old, new) != old);
+
+       return 0;
+}
+
+static inline int
 kref_put(struct kref *kref, void (*release)(struct kref *))
 {
 



Home | Main Index | Thread Index | Old Index