summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2015-09-11 19:22:38 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2015-09-11 19:22:38 +0000
commit478f3dae60533b42e512287c9e40fb04e6118ce0 (patch)
treea40c9b0dbddbd5d750da774aefc86d382703cc2d /sys
parentf6476ad96a84b508a3f347ba3b8974d355b73776 (diff)
make srp use refcnts so it can use refcnt_finalize instead of
sleep_setup/sleep_finish.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_srp.c25
-rw-r--r--sys/sys/srp.h8
2 files changed, 12 insertions, 21 deletions
diff --git a/sys/kern/kern_srp.c b/sys/kern/kern_srp.c
index 8d65b04615c..873c1ee2272 100644
--- a/sys/kern/kern_srp.c
+++ b/sys/kern/kern_srp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_srp.c,v 1.4 2015/09/11 14:08:03 dlg Exp $ */
+/* $OpenBSD: kern_srp.c,v 1.5 2015/09/11 19:22:37 dlg Exp $ */
/*
* Copyright (c) 2014 Jonathan Matthew <jmatthew@openbsd.org>
@@ -19,9 +19,7 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/atomic.h>
-
+#include <sys/timeout.h>
#include <sys/srp.h>
void srp_v_gc_start(struct srp_gc *, struct srp *, void *);
@@ -39,7 +37,7 @@ srp_gc_init(struct srp_gc *srp_gc, void (*dtor)(void *, void *), void *cookie)
{
srp_gc->srp_gc_dtor = dtor;
srp_gc->srp_gc_cookie = cookie;
- srp_gc->srp_gc_refcount = 1;
+ refcnt_init(&srp_gc->srp_gc_refcnt);
}
void
@@ -54,7 +52,7 @@ srp_update_locked(struct srp_gc *srp_gc, struct srp *srp, void *nv)
void *ov;
if (nv != NULL)
- atomic_inc_int(&srp_gc->srp_gc_refcount);
+ refcnt_take(&srp_gc->srp_gc_refcnt);
/*
* this doesn't have to be as careful as the caller has already
@@ -129,8 +127,7 @@ srp_v_dtor(struct srp_gc *srp_gc, void *v)
{
(*srp_gc->srp_gc_dtor)(srp_gc->srp_gc_cookie, v);
- if (atomic_dec_int_nv(&srp_gc->srp_gc_refcount) == 0)
- wakeup_one(&srp_gc->srp_gc_refcount);
+ refcnt_rele_wake(&srp_gc->srp_gc_refcnt);
}
void
@@ -174,7 +171,7 @@ void
srp_update(struct srp_gc *srp_gc, struct srp *srp, void *v)
{
if (v != NULL)
- atomic_inc_int(&srp_gc->srp_gc_refcount);
+ refcnt_take(&srp_gc->srp_gc_refcnt);
v = atomic_swap_ptr(&srp->ref, v);
if (v != NULL)
@@ -184,15 +181,7 @@ srp_update(struct srp_gc *srp_gc, struct srp *srp, void *v)
void
srp_finalize(struct srp_gc *srp_gc)
{
- struct sleep_state sls;
- u_int r;
-
- r = atomic_dec_int_nv(&srp_gc->srp_gc_refcount);
- while (r > 0) {
- sleep_setup(&sls, &srp_gc->srp_gc_refcount, PWAIT, "srpfini");
- r = srp_gc->srp_gc_refcount;
- sleep_finish(&sls, r);
- }
+ refcnt_finalize(&srp_gc->srp_gc_refcnt, "srpfini");
}
static inline void *
diff --git a/sys/sys/srp.h b/sys/sys/srp.h
index 62916b8928e..ed757479f0d 100644
--- a/sys/sys/srp.h
+++ b/sys/sys/srp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: srp.h,v 1.3 2015/09/09 11:21:51 dlg Exp $ */
+/* $OpenBSD: srp.h,v 1.4 2015/09/11 19:22:37 dlg Exp $ */
/*
* Copyright (c) 2014 Jonathan Matthew <jmatthew@openbsd.org>
@@ -19,6 +19,8 @@
#ifndef _SYS_SRP_H_
#define _SYS_SRP_H_
+#include <sys/refcnt.h>
+
struct srp {
void *ref;
};
@@ -33,13 +35,13 @@ struct srp_hazard {
struct srp_gc {
void (*srp_gc_dtor)(void *, void *);
void *srp_gc_cookie;
- u_int srp_gc_refcount;
+ struct refcnt srp_gc_refcnt;
};
#ifdef _KERNEL
#define SRP_INITIALIZER() { NULL }
-#define SRP_GC_INITIALIZER(_d, _c) { (_d), (_c), 1 }
+#define SRP_GC_INITIALIZER(_d, _c) { (_d), (_c), REFCNT_INITIALIZER() }
void srp_startup(void);
void srp_gc_init(struct srp_gc *, void (*)(void *, void *), void *);