From 7ede6d888ce643e68a37e09f8499ef2555a38c4e Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 24 Sep 2004 05:54:32 +0000 Subject: Introduce dev_re[lf]thread() functions. dev_refthread() will return the cdevsw pointer or NULL. If the return value is non-NULL a threadcount is held which much be released with dev_relthread(). If the returned cdevsw is NULL no threadcount is held on the device. --- sys/kern/kern_conf.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'sys/kern/kern_conf.c') diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 46fca85..e3e9495 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -84,12 +84,14 @@ dev_lock(void) void dev_unlock(void) { + mtx_unlock(&devmtx); } void dev_ref(struct cdev *dev) { + dev_lock(); dev->si_refcount++; dev_unlock(); @@ -107,6 +109,29 @@ dev_rel(struct cdev *dev) freedev(dev); } } +struct cdevsw * +dev_refthread(struct cdev *dev) +{ + struct cdevsw *csw; + + mtx_assert(&devmtx, MA_NOTOWNED); + dev_lock(); + csw = dev->si_devsw; + if (csw != NULL) + dev->si_threadcount++; + dev_unlock(); + return (csw); +} + +void +dev_relthread(struct cdev *dev) +{ + + mtx_assert(&devmtx, MA_NOTOWNED); + dev_lock(); + dev->si_threadcount--; + dev_unlock(); +} int nullop(void) -- cgit v1.1