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:
parent
fb9540a0dc
commit
2c15afd888
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=135704
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user