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.
This commit is contained in:
Poul-Henning Kamp 2004-09-24 05:54:32 +00:00
parent fb9540a0dc
commit 2c15afd888
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=135704
2 changed files with 28 additions and 0 deletions

View File

@ -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)

View File

@ -61,6 +61,7 @@ struct cdev {
#define SI_DUMPDEV 0x0080 /* is kernel dumpdev */
#define SI_CANDELETE 0x0100 /* can do BIO_DELETE */
#define SI_CLONELIST 0x0200 /* on a clone list */
#define SI_ISDISK 0x0400 /* device is a disk */
struct timespec si_atime;
struct timespec si_ctime;
struct timespec si_mtime;
@ -261,6 +262,8 @@ int clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **
int count_dev(struct cdev *_dev);
void destroy_dev(struct cdev *_dev);
struct cdevsw *devsw(struct cdev *_dev);
struct cdevsw *dev_refthread(struct cdev *_dev);
void dev_relthread(struct cdev *_dev);
const char *devtoname(struct cdev *_dev);
int dev_named(struct cdev *_pdev, const char *_name);
void dev_depends(struct cdev *_pdev, struct cdev *_cdev);