summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-23 10:56:21 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-23 10:56:21 +0000
commit875c5639e067b77cc8258a7b1d826c6178fb55e0 (patch)
treea5ebf8c330f1dc21cd21f298f124c02b08d35050 /sys
parent90ffe301366d97266117c7713a9e2a30bf493161 (diff)
Do not include <sys/atomic.h> inside <sys/refcnt.h>.
Prevent lazy developers, like David and I, to use atomic operations without including <sys/atomic.h>. ok dlg@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_srp.c3
-rw-r--r--sys/kern/kern_synch.c21
-rw-r--r--sys/sys/refcnt.h11
3 files changed, 26 insertions, 9 deletions
diff --git a/sys/kern/kern_srp.c b/sys/kern/kern_srp.c
index d1ad6122481..324e45bd3b3 100644
--- a/sys/kern/kern_srp.c
+++ b/sys/kern/kern_srp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_srp.c,v 1.6 2015/09/11 20:21:01 dlg Exp $ */
+/* $OpenBSD: kern_srp.c,v 1.7 2015/11/23 10:56:19 mpi Exp $ */
/*
* Copyright (c) 2014 Jonathan Matthew <jmatthew@openbsd.org>
@@ -21,6 +21,7 @@
#include <sys/systm.h>
#include <sys/timeout.h>
#include <sys/srp.h>
+#include <sys/atomic.h>
void srp_v_gc_start(struct srp_gc *, struct srp *, void *);
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 35fa6b460b2..0261a0309ce 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.125 2015/09/28 21:02:12 deraadt Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.126 2015/11/23 10:56:20 mpi Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -49,6 +49,7 @@
#include <sys/syscallargs.h>
#include <sys/pool.h>
#include <sys/refcnt.h>
+#include <sys/atomic.h>
#include <ddb/db_output.h>
#include <machine/spinlock.h>
@@ -598,6 +599,24 @@ sys___thrwakeup(struct proc *p, void *v, register_t *retval)
}
void
+refcnt_init(struct refcnt *r)
+{
+ r->refs = 1;
+}
+
+void
+refcnt_take(struct refcnt *r)
+{
+ atomic_inc_int(&r->refs);
+}
+
+int
+refcnt_rele(struct refcnt *r)
+{
+ return (atomic_dec_int_nv(&r->refs) == 0);
+}
+
+void
refcnt_rele_wake(struct refcnt *r)
{
if (refcnt_rele(r))
diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h
index 78fd0ddf4b9..3d699ea8fd2 100644
--- a/sys/sys/refcnt.h
+++ b/sys/sys/refcnt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: refcnt.h,v 1.2 2015/09/13 09:05:33 dlg Exp $ */
+/* $OpenBSD: refcnt.h,v 1.3 2015/11/23 10:56:20 mpi Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
@@ -27,12 +27,9 @@ struct refcnt {
#define REFCNT_INITIALIZER() { .refs = 1 }
-#include <sys/atomic.h>
-
-#define refcnt_init(_r) do { (_r)->refs = 1; } while (0)
-#define refcnt_take(_r) atomic_inc_int(&(_r)->refs)
-#define refcnt_rele(_r) (atomic_dec_int_nv(&(_r)->refs) == 0)
-
+void refcnt_init(struct refcnt *);
+void refcnt_take(struct refcnt *);
+int refcnt_rele(struct refcnt *);
void refcnt_rele_wake(struct refcnt *);
void refcnt_finalize(struct refcnt *, const char *);