Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 11:39:00 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/include/linux: kref.h

Log Message:
Provide kref_put_lock

Author: Maya Rashish <m...@netbsd.org>
Committer: Taylor R Campbell <riastr...@netbsd.org>


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/include/linux/kref.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/kref.h
diff -u src/sys/external/bsd/drm2/include/linux/kref.h:1.10 src/sys/external/bsd/drm2/include/linux/kref.h:1.11
--- src/sys/external/bsd/drm2/include/linux/kref.h:1.10	Sun Dec 19 10:48:37 2021
+++ src/sys/external/bsd/drm2/include/linux/kref.h	Sun Dec 19 11:39:00 2021
@@ -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 @@ kref_sub(struct kref *kref, unsigned int
 }
 
 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 *))
 {
 

Reply via email to